Jump to content

Recommended Posts

Greetings,

 

I am writing a small script to convert from .jpg to .gif

 

$filename = $_GET['file']; // always .jpg
$type = $_GET['type'];

$im = @imagecreatefromjpeg($filename);
if ($im === false)
{
die('Unable to open image');
}
if ($type == "gif")
{		
header ('Content-Type: image/gif');
        imagegif($im);
        imagedestroy($im);
}

 

This script displays the image on the browser page, whereas I would like to actually have a variable pointing to the relative path, ie. $location = "http://www.xx.com/uploads/image.gif"

 

Any suggestions? I read that imagegif($im,$destination); can be used, but it's giving me errors..

Link to comment
https://forums.phpfreaks.com/topic/64812-solved-convert-image-and-save-to-disk/
Share on other sites

Solution..

 

$filename = $_GET['file'];
$type = $_GET['type'];

$im = @imagecreatefromjpeg($filename);
if ($im === false)
{
die('Unable to open image');
}

srand((double)microtime()*1000000); 
$rand = rand(999999,99999999);

$dest = "../temps/" . $rand;

if ($type == "gif")
{		
	$dest .= ".gif";
	imagegif($im,$dest);
        imagedestroy($im);
        $filename = $dest;
}
if ($type == "png")
{
	$dest .= ".png";
	imagepng($im,$dest);
        imagedestroy($im);
        $filename = $dest;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.