<?php $source="bla.jpeg"; $max_x='140px'; $max_y='140px'; if(exif_imagetype($source) == IMAGETYPE_JPEG){ $img_src = imagecreatefromjpeg($source); }elseif(exif_imagetype($source) == IMAGETYPE_GIF){ $img_src = imagecreatefromgif($source); }elseif(exif_imagetype($source) == IMAGETYPE_PNG){ $img_src = imagecreatefrompng($source); }else{ } $image_x = imagesx($img_src); $image_y = imagesy($img_src); if($image_x > $image_y){ //landscape $ratio = ($image_x > $max_x) ? $max_x/$image_x : 1; }else{ //portrait $ratio = ($image_y = $max_y) ? $max_y/$image_y : 1; } $new_x = $image_x*$ratio; $new_y = $image_y*$ratio; $new_img = imagecreatetruecolor($new_x, $new_y); imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_x, $new_y, $image_x, $image_y); if(exif_imagetype($source) == IMAGETYPE_JPEG){ imagejpeg($new_img); }elseif(exif_imagetype($source) == IMAGETYPE_GIF){ imagegif($new_img); }elseif(exif_imagetype($source) == IMAGETYPE_PNG){ imagepng($new_img); } ImageDestroy($img_src); ImageDestroy($new_img); ?>
W tym skrypcie są zachowane proporcje, a ja chciałbym aby właśnie to max width i height zamieniło się w szerokość i wysokość wymuszoną, czyli zawsze taką samą niezależną od obrazka. Pozdrawiam