Hello. Tell me please. I encountered such a problem: I need to make a small copy of the picture, but I cannot find out the file extension. Here is the compression code:
list($width, $height) = getimagesize($fileName); $new_width = 200; $new_height = 160; if(strstr($fileName, '.png') || strstr($fileName, '.PNG')) { $image = imagecreatefrompng($fileName); } else if(strstr($fileName, '.jpg') || strstr($fileName, '.JPG') || strstr($fileName, '.jpeg') || strstr($fileName, '.JPEG')) { $image = imagecreatefromjpeg($fileName); } else if(strstr($fileName, '.gif') || strstr($fileName, '.GIF')) { $image = imagecreatefromgif($fileName); } $image_p = imagecreatetruecolor($new_width, $new_height) or die('Cannot initialize new GD image stream.'); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); function addThumb($fileName) { $fileName = array_reverse(explode('.', $fileName)); $fileName[0] = 'smpgthumb.'.$fileName[0]; $fileName = implode('.', array_reverse($fileName)); return $fileName; }
It seems that everything should work, but the $fileName
variable has values of the form my_photo.jpeg
or my_photo.gif
, etc. and etc. .... how can I compress in this case?
Thank you in advance!