Hello,
I tried to alter my script so that it would convert any pngs or gifs to jpeg but for some reason it keeps a gif a gif. I found one post saying that all I needed to do was change the imagegif to imagejpeg at the end so I remmed out all of the lines on the following code except for imagejpeg($img, $thumb_path); but it still creates a gif.
if ($ext == 'jpg' || $ext == 'jpeg') {
imagejpeg($img, $thumb_path);
} else if ($ext == 'png') {
imagepng($img, $thumb_path);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
imagegif($img, $thumb_path);
}
I then unremmed it all and tried adding $ext='jpeg' above it but still no go.
I then tried to change the filename earlier in the script after it created the filefromgif
$img2 = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = @imagecreatefrompng($image_path);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
$img = @imagecreatefromgif($image_path);
}
ADDED:
$img = str_replace("gif", "jpg", $img);
I think that it's pulling the filename from the DB and naming it back to it after the imagecreate line and then maybe creating a jpeg named with a gif extension? You got me. I've been at this for 4 hours now. Heres the whole script:
$size=60;
$getpic = "SELECT image, bandid from band_page WHERE bandid=382";
$picresult = mysql_query($getpic, $conn) or die(mysql_error());
if(mysql_num_rows($picresult)){
while($row9 = mysql_fetch_assoc($picresult)){
$image = $row9['image'];
$bandid = $row9['bandid'];
$image_file = str_replace('..', '', $image);
$image_path = "bandpics/$image_file";
$thumb_path = "bandpics/thumbs/$image";
# Load image
$img2 = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = @imagecreatefrompng($image_path);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
$img = @imagecreatefromgif($image_path);
}
# If an image was successfully loaded, test the image for size
if ($img) {
# Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
if ($width<=$height)
{
$new_height=$size;
$new_width=$size;
//$new_width = ($new_height/$height)*$width;
}
else
{
$new_width=$size;
$new_height=$size;
//$new_height = ($new_width/$width)*$height;
}
# Create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
# Copy and resize old image into new image
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
//if ($ext == 'jpg' || $ext == 'jpeg') {
imagejpeg($img, $thumb_path);
//} else if ($ext == 'png') {
//imagepng($img, $thumb_path);
# Only if your version of GD includes GIF support
//} else if ($ext == 'gif') {
//imagegif($img, $thumb_path);
//}
}}
}