Crop image script

So you have a wordpress website and you have a form where user enters data, you have given an ‘upload image’ option but you want the uploaded images to be cropped for proper display ?
Below is the code that might help you crap crop it.

How to use it

Just paste the above code in functions.php file of your active wordpress theme. Then call the function wdw_crop_img passing proper parameters.

The above function out of the box is ‘wordpress specific’ because line no 23 in the code makes use of wordpress core function to get to the uploads directory (check line no 23, 25, 26 in the code). But you can obviously modifyl those 3 lines to suit to your website’s directory structure and make it work on any non-wordpress php website.

Rest, read the comment section above function declaration to figure out about the parameters passed and output.

Drop in your comment if you find any problem.
That’s it in here. Hope you find it useful.

Published by

Chandan Chaudhary

Chandan is a WordPress guy. A programmer at heart. He loves building community sites with WordPress and BuddyPress.

2 thoughts on “Crop image script”

  1. Thank you for such a nice code.
    Works perfectly…!

    Can you guide how one can modify your code to use it with image cropping using JCrop?

Leave a Reply

Your email address will not be published. Required fields are marked *