Page 1 of 1

Croping and Image Resize while upload

Posted: Fri May 12, 2017 1:49 pm
by innovativeshadow

Please give a option to crop and resize a image while upload, at least a extension that can do it with modula dialog.
Thank you.


Re: Croping and Image Resize while upload

Posted: Fri May 12, 2017 3:35 pm
by Webmaster

If you have enabled resize in Edit Tag panel, you can use Row_Inserting/Updating server event (see Server Events and Client Scripts in the help file) and add plugin(s) for resizing to the Upload object of the file upload field, e.g.

$this->MyFileUploadField->Upload->Plugins[] = function($thumb) {
$thumb->cropFromCenter(400, 300);
};

The $thumb is an instance of a subclass of GD (extends PHPThumb) class which has crop() and cropFromCenter() and adaptiveResize*() methods (see source code of PHPThumb.php), you can crop and/or resize the image. (Resizing will still be done later according to your project settings.)


Re: Croping and Image Resize while upload

Posted: Sun Nov 28, 2021 12:32 pm
by Bishu

I am using PHPMaker 2022.0.6

I want to upload a Photo and choose the portion to crop as per my requirement
Under Edit Tag -
Resize Image is enabled

under the Server Script -> Table Specific ->Common->Row_Inserting

$this->Photo->Upload->Plugins[] = function($thumb) {
        $thumb->cropFromCenter(400, 300);
    };

The photo is uploaded and i did not get the option for cropping.


Re: Croping and Image Resize while upload

Posted: Sun Nov 28, 2021 6:52 pm
by arbei

It should work. Was the image resized? If so, it should also have been cropped.

Note that cropping by PHPThumb is done on server side after upload, it won't let user "choose the portion to crop". If you use cropFromCenter(), you need to make sure the users upload images with the portion you need at the center.

Make sure the resized image is larger than the cropping size or there is nothing to crop.


Re: Croping and Image Resize while upload

Posted: Sun Nov 28, 2021 11:03 pm
by Bishu

I want the user should allow to select the portion for cropping

I have install the cropperjs ^1.5.12 from Tool->npm packages
but unable to implement it in the field.


Re: Croping and Image Resize while upload

Posted: Mon Nov 29, 2021 12:39 pm
by arbei

This may not be simple, but should be viable. PHPMaker uses jQuery File Upload, which supports processQueue, you should be able to add a process action to call Cropper.js in a modal dialog (see source in the example) for user to crop.