Imagecopy - crop image instead of resizing

I want to resize - $artfileand put the store in $deststarting with $start_x, $start_y.

$destcontains a frame. $artfileshould be framed, so I need to resize it.

my code is:

imagecopy($dest, $art_file, $start_x, $start_y, 0, 0, $new_width, $new_height); // works fine but to test resize

$dest = my destination resource
$artfile = resource that I want to patch with $destination
$new_width, $new_height = I want $art_file to be resized to this value, without trimming off or cropping. 

My problem:

For any images that are larger than $new_heightor $new_widthlarger, the more they are cropped. I want to resize the entire set to $new_heightor $new_width.

Any help?

+4
source share
1 answer

play with it, hope it helps you with it;

 <?php
 Function createthumbnail($src=null,$newHeight=null) {
    $srcimg = imagecreatefromjpeg($src);
    $srcsize = getimagesize($src);
    $dest_y = $newHeight;
    $dest_x = ($newHeight / $srcsize[1]) * $srcsize[0];
    $thumbimg = imagecreatetruecolor($dest_x, $dest_y);
    imagecopyresampled($thumbimg,$srcimg,0,0,0,0,$dest_x,$dest_y, $srcsize[0], $srcsize[1]);
    $thumbimg = imagejpeg($thumbimg,$src);
    return $thumbimg;
}
?>

you can call it like this

<?php
resizedImage = createthumbnail(urlOfFileToResize,newHeight);//newHeight would be like 1 or 50 or 1000......
?>

now your resized image will be saved in resizedImage

Welcome.

0

All Articles