Jump to content

Remaking & compressing images (works for jpeg, not png or gif)


anderson_catchme

Recommended Posts

function create_image($ext, $filepath, $newfilepath, $jpegquality){
switch ($ext){
case "jpg" OR "jpeg":
    $im = @imagecreatefromjpeg($filepath);
    if($im){
    imagejpeg($im, $newfilepath, $jpegquality);
}
break;
case "gif":
    $im = @imagecreatefromgif($filepath);
    if($im){
    imagegif($im, $newfilepath);
}
break;
case "png":
    $im = @imagecreatefrompng($filepath);
    if($im){
    imagepng($im, $newfilepath, 7);
}
break;
    }
if(!$im){
return FALSE;
    }
}

 

$ext is my file extention. The rest is pretty self explanitory. It's working for JPEG, but somehow not PNG or GIF. Not sure why, help appreciated. Thanks.

case "jpg" OR "jpeg":
Can't do that. It's like saying

if ($ext == ("jpg" OR "jpeg")) {
which means

if ($ext == true) {
which will always be the case for strings like "jpg" or "png".

 

Use multiple cases instead.

case "jpg":
case "jpeg":
    // ...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.