Jump to content


Photo

Image Cropping


  • Please log in to reply
11 replies to this topic

#1 dustinto

dustinto
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 June 2006 - 06:41 PM

I want to make a program that will be able to take an image file and crop a square at a given coordinate value (X,Y).

I would tell it the X,Y and the size of the crop ie. 350x350. The X,Y would be the center of the newly created image.

I'm sure this can be done but I get a little lost when looking at all the different documents on how to go about doing this. Hopefully someone here can help me out.

Thanks for you help

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 13 June 2006 - 08:13 PM

SOmething like this

Save in ::crop.php ::
<?php
$file = $_GET['file'];
$x = $_GET[x];
$y = $_GET['y'];

$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor(350, 350);

imagecopyresized($dst,$src,0,0,$x-175,$y-175,350,350,350,350);

imagejpeg($dst);
imagedestroy($dst);
imagedestroy($src);
?>

Place on page with
<IMG src='crop.php?file=myimage.jpg&x=500&y=500' width='350' height='350'>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 dustinto

dustinto
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 14 June 2006 - 11:36 AM

Thanks. Do I need to install something special to get this to work?

I am getting this error...

Fatal error: Call to undefined function: imagecreatefromjpeg() in /home/holderc/public_html/resizer/crop.php on line 6


#4 crouchjay

crouchjay
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 14 June 2006 - 01:12 PM

You need to install GD 2.0
Don't worry this is very easy. You can look for instructions on the official page. Don't have it right now, but you can google it.

Basicly,

You find the code snip in php.ini.recommend and unmark it. <- forget the actuall word describing the action

so it will look like this -> extension=php_gd2.dll
instead of -> ;extension=php_gd2.dll


Jay

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 14 June 2006 - 01:13 PM

All image functions require GD graphics extension
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 dustinto

dustinto
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 14 June 2006 - 02:56 PM

I got that installed and it worked great. Thanks

Now is their some way I could make the image transparent?

I want to display two images that will be cropped using the above tool and then have a third one that will be the two images on top of each other with one being transparent.

Thanks

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 14 June 2006 - 06:19 PM

imagecopymerge() has a transparency argument.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 dustinto

dustinto
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 June 2006 - 11:42 AM

Thanks I got that both of those working.

I had to set the script to save the newly cropped images before making them transparent, because it would crash the server if I tried to crop and make them transparent in one action. Guess since the files are so big.


I do have another question.

Do you happen to know if there is anyway to draw a box on the image and save it. It would be used to highlight an area...would be a nice feature, but I can do that manually if it can't be done.

After cropping 230 of these manaully last week (in powerpoint - 70 slides) I would like to make as much of the process automated as I can. Since we are going to be using this process on all new jobs :(

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 15 June 2006 - 12:31 PM

imagerectangle()
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 dustinto

dustinto
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 June 2006 - 12:37 PM

[!--quoteo(post=384149:date=Jun 15 2006, 12:31 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 15 2006, 12:31 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
imagerectangle()
[/quote]

I found the command, but I wasn't sure of some way to physically click on the image and make the rectangle. Maybe with javascript

#11 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 15 June 2006 - 12:47 PM

Place image in a form
<input type='image' name='mypic' src='myimage.jpg>

Whe user clicks on image, x,y coords are posted in $_POST['mypic_x'] and $_POST['mypic_y']
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#12 dustinto

dustinto
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 June 2006 - 01:41 PM

The only problem I have now is that the imagerectangle() function needs two x , y values.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users