Jump to content

Archived

This topic is now archived and is closed to further replies.

dustinto

Image Cropping

Recommended Posts

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

Share this post


Link to post
Share on other sites
SOmething like this

Save in ::crop.php ::
[code]<?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);
?>[/code]

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

Share this post


Link to post
Share on other sites
Thanks. Do I need to install something special to get this to work?

I am getting this error...

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
[!--quoteo(post=384149:date=Jun 15 2006, 12:31 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 15 2006, 12:31 PM) [snapback]384149[/snapback][/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

Share this post


Link to post
Share on other sites
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']

Share this post


Link to post
Share on other sites
The only problem I have now is that the imagerectangle() function needs two x , y values.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.