Crop Image Like Orkut

05 Jun 2008

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/

Tags: , , , ,

· · · ◊ ◊ ◊ · · ·

Introduction >>

Online Photoshop in PHP (Series Part 1)

As i announced in my birthday post: celebrating-1st-year-of-sajithmr.com , i am starting my post series How to make Photoshop Express in PHP

Before we starting the step by step procedure, have a look at : http://www.sajithmr.me/photoshop/index.php

This is a basic version of online photo editing tool.

You can either upload a photo to this tool or you can browse some images already supplied.

The basic features are:

  1. Crop
  2. Resize
  3. Water marking (Both logo and text)
  4. Round corner
  5. Rotate
  6. Download and save

Try yourself

Upload some picture (or browse any picture), Press crop button (top left), you can see orkut photo upload like crop there. You can select the area, or drag anywhere in the image. Press crop button in the workdesk. (Press F11 or fullscreen view for better performance )

Try all other features provided.

The whole site is divided into four parts.

  1. Tools
  2. Work Desk
  3. Browse Photos
  4. Settings

Tools area contains options for crop, resize, watermark, round, undo , save, clear all, download.

Here ‘clear all’ reset all the operations and navigate the website into initial settings.

From the Settings Area, You can fix the angle of the image. You can rotate either clock-wise or anti-clock-wise depending on the angle provided (+ve or -ve)

In Text Water Mark Setting Area, you can enter a text, set font size and font color. It generates a pictures corresponding to your text. Click water mark button in tool area and fix the position , press Apply Watermark

You can also upload your water mark logo.

Finally you can download the edited picture by clicking download button in the Tool area (top right) .

The interesting thing is the whole website / tool is created in a single day.

wanna learn how to implement this ??

Keep reading rest of the series.

In Online Photoshop in PHP (Series Part 2) >> Implementation of the Browse Photos Area

Thanks and Regards
Sajith M.R

Tags: , , , , , , , , , ,

· · · ◊ ◊ ◊ · · ·

وظائف 2011 تحويل العملات برامج برنامج تسريع التحميل برنامج الفلاش برنامج محول الصوتيات عربي hotel 2011 زيادة رواتب العساكر 1431