I've got this code:
<?php
$obrazek = $row["image_name"];
$file = "../../uploads/$obrazek";
$pathToSave = "../../uploads/thumbnail/";
$what = getimagesize($file);
$w = $what[0];
$h = $what[1];
$size = 500/$w;
$l = floor($w*$size);
$a = floor($h*$size);
$file_name = basename($file);
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$file_name = basename($file_name, ".$ext") . '.' . $ext;
switch(strtolower($what['mime']))
{
case 'image/png':
$img = imagecreatefrompng($file);
$new = imagecreatetruecolor($l,$a);
imagecopy($new,$img,0,0,0,0,$l, $a);
break;
case 'image/jpeg':
$img = imagecreatefromjpeg($file);
$new = imagecreatetruecolor($l,$a);
imagecopy($new,$img,0,0,0,0,$l, $a);
break;
case 'image/gif':
$img = imagecreatefromgif($file);
$new = imagecreatetruecolor($l,$a);
imagecopy($new,$img,0,0,0,0,$l, $a);
break;
default: die();
}
imagejpeg($new,$pathToSave.$file_name);
imagedestroy($new);
it's working, but it's cropping image, how can I change it for saving the image in thumbnail size without cropping? Where is the wrong part of this code?
Here is original and here is thumbnail with cropping