PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
<?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?
Last edited by tristanlee85 on Sat Dec 20, 2003 4:31 pm, edited 1 time in total.
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.
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
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?
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.
<?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>