Crop Image Like Orkut

Online Photoshop in PHP (Series Part 4) >>

Crop Image Like Orkut

Today we will discuss about cropping of images using php and gd library.

Look at the simple example here:

http://www.sajithmr.com/photoshop-tuts/crop/simplecrop.php


$x1 = $_GET['x1'];
$y1 = $_GET['y1'];

$x2 = $_GET['x2'];
$y2 = $_GET['y2'];	

$image_object =   imagecreatefromjpeg('hari.jpg');
$image_cropped =  Crop($image_object,$x1, $y1, $x2,$y2);
$temp_path = rand(1,99999)."hari.jpg";
imagejpeg( $image_cropped,$temp_path);

header('Location: simplecrop.php?img='.$temp_path );	  

?>

Here the Crop function is doing the real work. x1 and y1 are Top-Left Coordinates of new image and x2, y2 are the Bottom-Right .

Here is the function for Crop

function Crop($image, $xpos1,$ypos1,$xpos2,$ypos2)
	{
		require_once('class.cropcanvas.php');
		$cc =& new CropCanvas();
		$cc->loadImageFromObject($image);
		$cc->cropToDimensions($xpos1, $ypos1, $xpos2,$ypos2 );
		return $cc->getImageObject();

	}

?>

You can see the class.cropcanvas.php file from the attachment.

In the above example, we have to enter each coordinates manually. See the example below:

http://www.sajithmr.com/photoshop-tuts/crop/realcrop.php

Here you can select the area by click and drag (like orkut)

This is implemented with the help or jslib javascript. The given attachment in the end of this post contains the all.

http://www.sajithmr.com/photoshop-tuts/crop.zip

Keep reading for the further posts in this series. Next post is on Intellegent watermarking on images.

Subscribe to my Feeds: http://www.sajithmr.com/feed/

19 Comments , , , ,

19 Responses to “Crop Image Like Orkut”

  1. jithesh August 5, 2008 at 12:08 pm #

    Thanks…nice one

  2. Noah October 7, 2008 at 6:09 am #

    Someone should make a “facebook / flickr” style image tagging script based on this where you can tag people or interesting things in a photo. I’m sure the right person could do it!

  3. developer November 24, 2008 at 8:25 pm #

    Hey thank you so much
    as it too important for me when this functionality i was impleting in my site and not found proper soluntion.

    this code is realy usefull for me

    Thank you :)

  4. jasan December 12, 2008 at 5:03 pm #

    Hi,

    Really Very Nice Tutorial. This is exactly what i want.

    Thank you so much.

  5. pradeep pathak January 14, 2009 at 5:40 pm #

    Thanks for the code. Works Nice. Actually I was looking for a Orkut like photo upload script. If you have any like that, I would be highly thankful.

  6. Chris January 14, 2009 at 10:16 pm #

    Very impressive!

    I have a newbie question though. How would I lock the aspect ratio for the realcrop example (like 6×4 or 3×5)?

    Thanks.

  7. harry January 28, 2009 at 12:21 pm #

    if i want to crop image in square mode then what function i have to change please reply fast

    thanks

  8. Cléber February 10, 2009 at 5:57 pm #

    Harry, use this:
    Event.observe(
    window,
    ‘load’,
    function() {
    new Cropper.Img(
    ‘cropimage’,
    {
    onEndCrop: onEndCrop,
    ratioDim:{x:7.6923,y:10},
    }
    )
    }
    );
    Set the proportions to 1/1 in the “ratioDim” line.

  9. manoj March 25, 2009 at 12:35 pm #

    Hey m geting problem to corp photo on my orkut site

  10. Eduardo April 25, 2009 at 10:45 pm #

    You know where I can find a plugin for wordpress with the function of crop image? Thank you.

  11. sheetal July 15, 2009 at 3:21 pm #

    thanks
    it’s very nice and useful script

  12. mag July 23, 2009 at 5:43 pm #

    Hi,

    I liked your script for image croping but is it possible for us to show by default the crop borders on the image

  13. frankred September 29, 2009 at 6:04 pm #

    The Script is offline, can you send it to me via Mail?

  14. kishan November 18, 2009 at 3:45 pm #

    script is now not available can u send it me via mail or give me new url???

  15. Sanowar January 29, 2010 at 1:22 pm #

    I liked your script for image croping but it is showing errror in IE

  16. Christin joseph May 30, 2010 at 8:43 am #

    Wow

  17. nitin June 10, 2010 at 10:23 pm #

    this link is not working……plz any body mail me on this id: nitinhappy2@gmail.com ……………..thnx in advance…….i really need it plz mail me this script as soon as possible…….thanks again

    • Sajith M.R June 11, 2010 at 4:11 am #

      yes, nithin , unfortunately, i got virus attack in my server and lost all those source codes :(

  18. Amit May 1, 2011 at 1:12 pm #

    Hey buddy it not working now…says “404 page nt found”

Leave a Reply

More in Downloads, php, php source code (61 of 115 articles)


  If you want to get the FLV file of any youtube video url using php code, here is the ...