Crop and resize images in cakePHP

by edap
CakePHP helper and component to crop and resize images using jWindowCrop
I've just created an helper and a component to make images thumbs easy to create. The code is avaliable at this git repo.
I've used jWindowCrop, a jquery plugin, in order to create the crop interface. There are a lot of plugins out there to do this particular job, probably the mosts famous are Jcrop and imgAreaSelect. I've tried both of them, they are really well done and extremely powerfull, neverthless, i've prefered jWindowCrop for his clearer interface. There is only one window containing the picture that you want to crop, you can work directly on this one, using only 2 controls: the zoom and the drag movement.I think it's enough to do the job. I've found smart the way to avoid the preview picture, used in the others two plugin.
But sure, this works only if you know exactly the size of the picture that you want to obtain.
To install it in your application and start to crop the images that you have previously uploaded:
  • copy app/View/Helper/CropHelper.php in your app/View/Helper folder
  • copy app/Controller/Component/CropComponent.php in your app/Controller/Component folder
  • copy app/webroot/js/jwindowcrop folder in your webroot/js folder
  • Include jquery and the Elements/jwindowcrop.ctp in the view where you need to display the crop interface. Use the CropHelper inside a form, in order to generate the crop interface.See "View Example" in this blog entry.
  • In this same view, every image should be passed as an array. Set this array in the controller, and set the folder to store your images. Look at this example to see how to include the crop component.See "Controller Example" in this blog entry.


More on Helpers



login to post a comment.