php function crop image

Solutions on MaxInterview for php function crop image by the best coders in the world

showing results for - "php function crop image"
Lautaro
02 Mar 2017
1$image = imagecreatefromjpeg($_GET['src']);
2$filename = 'images/cropped_whatever.jpg';
3
4$thumb_width = 200;
5$thumb_height = 150;
6
7$width = imagesx($image);
8$height = imagesy($image);
9
10$original_aspect = $width / $height;
11$thumb_aspect = $thumb_width / $thumb_height;
12
13if ( $original_aspect >= $thumb_aspect )
14{
15   // If image is wider than thumbnail (in aspect ratio sense)
16   $new_height = $thumb_height;
17   $new_width = $width / ($height / $thumb_height);
18}
19else
20{
21   // If the thumbnail is wider than the image
22   $new_width = $thumb_width;
23   $new_height = $height / ($width / $thumb_width);
24}
25
26$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
27
28// Resize and crop
29imagecopyresampled($thumb,
30                   $image,
31                   0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
32                   0 - ($new_height - $thumb_height) / 2, // Center the image vertically
33                   0, 0,
34                   $new_width, $new_height,
35                   $width, $height);
36imagejpeg($thumb, $filename, 80);
queries leading to this page
image crop 2b phpphp crop image in serverimage crop and resize package in phpcrop phpphp crop uploaded imagecrop image from phpphp image magick crophow to store croped image on database phpjcrop image crop example phpphp upload image with crop exampleimage crop in php with urlimage cropping phpphp crop jpgphoto cropping tool phpcrop image php example change event not workingphp crop pngimage croping in phpphp crop image from righttools to crop images in phpcrop php imagephp image croppingimage crop code phpcrop phpphp imagick crop imageimage crop in jquery phpcrop image store phpphp function crop imageimage crop without file manipulation in phptuto crop image phpphp image crop toolphp to crop the imagephp crop center imagesave cropped image phpcrop image in phpphp image cropingphp crop imagecrop image in php with demohow to add a crop feature using phphow to display croped image phpimage cropping and saving in phpimage crop without croppie phphow to make an image cropper in phpphp crop pictureadaptive crop image phpcrop image and display with phpcropper phpcrop and rotate images in phpautomatic image cropping in phpimage croping code in phpimage cropping at the time of showing image in phpcropping a part of image in phpphp crop image brfore saveimage crop in phpcrop jpg phpphp image cropphp image resize and crophow to store cropped image on database phpimage cropper in phpphp image croppercrop image 200x200 in center in phpphp get image and crop with from urlcrop and download webpage in phpcropping image phpphp crop image from centercrop image with phpimage crop function in phpcrop image with javascript and phpphp crop imageimage crop center phpimage crop php examplephoto crop phpimage crop phpphp crop image resourcrimage crop and upload in phphow to crop videos phpcrop image php jpgcrop temporay for showing image in phpphp crop image centeredcrop image phpimage cropper phpimage crop jquery phpcrop image phppresentationimage cropper get original image in phphow to crop image in phplibrary to crop image phpcrop and upload image in phpphp crop image on servercenter crop image phpupload image and crop phpcrop the image in phpcrop phpto onlinephp cut imagesave cropped image in form phpupload cropped image phpimage cropper js phpimage crop with js and phpphp image x y cropcrop image with pixels in phpphp crop methodphp function crop image