Page 1 of 1
CHanging uploaded image from GIF to JPG
Posted: Sat Dec 20, 2003 6:50 am
by tristanlee85
In my gallery, only JPG thrumbnails will show up when using GD 2. I want to be able to resize GIF's so they also appear the same was as JPGs. Here is my config code:
Code: Select all
<?php
//Slide gallery variables
$col = 3; //no. of columns in a page
$maxrow = 3; //no. of rows in a page
$dir="."; //directory for this script, no need to change
$thumb = true ; //setting it to TRUE will generate real thumbnails on-the-fly, supports jpg file only and requires GD library. Setting it to FALSE will resize the original file to fit the thumbnail size, long download time. Turn it off if thumbnails don't show properly.
$place = "."; //directory of the slide mount images, no need to change
?>
Where you see "$thumb = true" is there any way I can make an 'if' statement so whenever there is a gif, it turns it to false, and back to true whenever there is a JPEG?
Posted: Sat Dec 20, 2003 8:50 am
by Gen-ik
You can load GIFs into GD and resize them etc but you can't export them as GIFs due to some legal reasons. The new version of GD will be released in 2004 and that will (we all hope) have full GIF support.
Posted: Sat Dec 20, 2003 10:10 am
by aquila125
PNG is the way to go.. it's the improved (and free) version of GIF
Posted: Sat Dec 20, 2003 10:39 am
by Gen-ik
Ah.. but PNG doesn't support animated files as far as I know. I'm hoping that when the new version of GD comes along it will allow people to create animated GIFs.. that will make PNG pretty much redundant.
On top of that more browsers support GIF than PNG.. but that's another story

Posted: Sat Dec 20, 2003 3:09 pm
by tristanlee85
I'm only worried about JPG and GIF because people will only be uploading those types of files to my server. You said I can use GD to resize GIFs, but how?
Posted: Sat Dec 20, 2003 3:33 pm
by Gen-ik
You just need to load the GIF and then save it as a JPEG.
Something similar to this..
Code: Select all
<?php
// Load the GIF
$im = imagecreatefromgif("images/myImage.gif");
// Then save it as a JPEG
imagejpeg($im, "images/myImage.jpg", 80);
?>
It might be worth checking the manual and reading up on what GD functions are available to you...
http://se.php.net/manual/en/ref.image.php
Posted: Sat Dec 20, 2003 3:42 pm
by tristanlee85
Well, I obviously don't know how to do this as easy as I thought I could. Here is what I have and it isn't working. BTW, this thumbs.php. It used GD to create a thumbnail of the JPG. I tried to have it take the GIF and save it as a JPG, but I must have something wrong.
Code: Select all
<?php
$uploaddir = $_SERVERї'DOCUMENT_ROOT'] . "\\saturnspot"e;; //replace the $uploaddir to wherever you want the files to go
$filename = $_FILESї'file']ї'name']; // get the filename
$filetype = $_FILESї'file']ї'type']; // get the file MIME type
// Load the GIF
$im = imagecreatefromgif("$filename");
// Then save it as a JPEG
imagejpeg($im, "$filename", 85);
$uploadfile = $uploaddir . $filename; //this is full path to where the file will go
if (empty($filename)) { //make sure the user selected a file
die ("Please select a file to upload!");
}
if ($filetype == "image/jpeg" || $filetype == "image/jpg" || $filetype == "image/gif") { //make sure file is .jpg or .gif
if (move_uploaded_file($_FILESї'file']ї'tmp_name'], $uploadfile)) { // move the file
echo "Thank you. The files was successfully uploaded.<br><br> To link to this files, please copy the following URL: <b>http://24.197.74.135/saturnspot/$filename</b>";
}
else {
echo "File upload failed";
}
}
else {
die ("Please only upload image files. Your file type was $filetype");
}
?>
<html>
<head></head>
<body>
<form action="index.php" method="post" ENCTYPE="multipart/form-data">
<input type="file" size=40 name="file"><br>
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="submit" value="upload">
</form>
To visit the SaturnSpot image gallery, click <a href="index.php">here</a>.
</body>
Posted: Sat Dec 20, 2003 4:11 pm
by tristanlee85
Maybe I should make this more clear: when the person uploads a GIF, i want it to automatically save it as a JPG instead of GIF.