Jump to content

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


anderson_catchme
Go to solution Solved by requinix,

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.

Link to comment
Share on other sites

  • Solution

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":
    // ...
Link to comment
Share on other sites

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.