Hi, I'm trying to resize and then crop an image. I found the following code for resizing an image.
<?php
// The file
$filename = $_GET['src'];
// Set a maximum height and width
$width = 256;
$height = 1000;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, null, 100);
?>
I thought that I could put the result into a variable like
$resized = imagejpeg($image_p, null, 100);
to then use with this code for cropping the image. Replacing the $_GET with the $resized variable
<?php
$x=0;
$y=0;
$filename=$_GET['src'];
header('Content-type:image/jpg');
header('Content-Disposition: attachment;filename='.$src);
list($width, $height, $type, $attr) = getimagesize($filename);
$w= $width ;
$h= 86;
$image=imagecreatefromjpeg($filename);
$crop=imagecreatetruecolor($w,$h);
imagecopy($crop,$image,0,0,$x,$y,$w,$h);
imagejpeg($crop);
?>
It seems though that I am wrong. Could someone help me with this? Thanks!