anderson_catchme Posted August 21, 2014 Share Posted August 21, 2014 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 https://forums.phpfreaks.com/topic/290583-remaking-compressing-images-works-for-jpeg-not-png-or-gif/ Share on other sites More sharing options...
requinix Posted August 21, 2014 Share Posted August 21, 2014 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 https://forums.phpfreaks.com/topic/290583-remaking-compressing-images-works-for-jpeg-not-png-or-gif/#findComment-1488580 Share on other sites More sharing options...
anderson_catchme Posted August 21, 2014 Author Share Posted August 21, 2014 Thanks. Working great now. Link to comment https://forums.phpfreaks.com/topic/290583-remaking-compressing-images-works-for-jpeg-not-png-or-gif/#findComment-1488581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.