Search code examples
phphtmlgdjcrop

Which is the better way to manipulate an image, using gd lib or using the FileReader() with Jcrop?


I am trying to resize and crop an image on a php page. I either want to use gd lib or jcrop with FileReader(). Which would be a better wat to go. what are the pros/cons ?


Solution

  • jcrop and FileReader() both are the frontend browser library or api,while gb lib is the php backend library.

    I have to two solutions FYI.

    1. jcrop+FileReader() for user crop the image,and then frontend get new the cropped image's data like {x:50,y:100,width:100,height:200} relative to original image,which will be posted to backend for php process gb lib( imagecrop function).

    pros: balance both frontend and backend performance. cons: code looks more complicated

    1. only jcrop+FileReader() for user crop the image,and them frontend get new the cropped image's base64 string,then post to the server.Server no need to call gb lib to crop.Just decode base64 image and save it as file.

    pros: code looks more simple. cons: increase frontend pressure. Save bandwidth (no need to upload original image)

    Finally,up to you to add more logic in frontend or backend.