Croping and Image Resize while upload

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
innovativeshadow
User
Posts: 86
Location: Almaty, Kazakhstan

Croping and Image Resize while upload

Post 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.


Webmaster
User
Posts: 9432

Post 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.)


Bishu
User
Posts: 429

Post 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.


arbei
User
Posts: 9536

Post 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.


Bishu
User
Posts: 429

Post 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.


arbei
User
Posts: 9536

Post 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.


Post Reply