0

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

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • Can you add samples of the images to show how it's cropping the images. – Nigel Ren Aug 18 '20 at 18:00
  • One thing I noticed from the duplicate is that in [their answer](https://stackoverflow.com/a/11376379/1213708), they use `imagecopyresized()` and not `imagecopy()`. – Nigel Ren Aug 18 '20 at 18:07

0 Answers0