verot / class.upload.php

This PHP class uploads files and manipulates images very easily. It is in fact as much as an image processing class than it is an upload class. Compatible with PHP 4, 5, 7 and 8. Supports processing of local files, uploaded files, files sent through XMLHttpRequest.
http://www.verot.net/php_class_upload.htm
GNU General Public License v2.0
846 stars 359 forks source link

Unable to crop image correctly #140

Closed exhaler closed 4 years ago

exhaler commented 4 years ago

Hello, using cropper https://github.com/fengyuanchen/jquery-cropper to crop an image before upload. I'm storing the crop values as hidden input fields in the form to submit.

However i'm unable to figure out how to crop the image correctly according to the selection i'm doing.

$file->image_resize = true;
$file->image_x = ceil($image_details['width']);
$file->image_y = ceil($image_details['height']);
// try another approach 
$file->image_resize = true;
$file->image_crop = '$x, $width, $y, $height' // values for top, right, bottom and left

Both options don't work.

Thanks for the help

verot commented 4 years ago

You need to use image_ratio_* alongside image_x and/or image_y.

As for image_crop, it accepts an array as a value, or a space delimited list of values; in your code, you are separating values with commas

exhaler commented 4 years ago

So i should send image_crop these values

x: the offset left of the cropped area
y: the offset top of the cropped area
width: the width of the cropped area
height: the height of the cropped area
verot commented 4 years ago

image_crop values are the number of pixels removed on each side. Please check the doc, and the demo.