Jun 5 2008

Crop Image Like Orkut

This entry is part 4 of 5 in the series Online Photoshop

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/

Series Navigation«Online Photoshop in PHP (Series Part 3)Intelligent Watermark (php + gd)»

TAGS: , , , ,

2 Comments on this post

Trackbacks

  1. jithesh said:

    Thanks…nice one

    August 5th, 2008 at 12:08 pm
  2. Noah said:

    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!

    October 7th, 2008 at 6:09 am

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog

Sponsors

    Advt on sajithmr.com
    Advt on sajithmr.com
    Advt on sajithmr.com
    Itslife Online

Recent Comments

  • Binny V A: Thanks for the post - love the picture ;-)
  • TheAnand: A lot of people are seeing errors with google video chat….is there any other software which has to be...
  • Alex: Wow, interresting analysis you have done! I’m trying to run GoogleVoiceAndVideoSetup on linux, using...
  • Mella Fitriansyah: Nice plugin, I will try to add this plugin in my blog…
  • Mella Fitriansyah: Nice Info, Sir i will reading your another post success for you

Recent Readers

JOIN MY COMMUNITY!

Recent Posts