dustinto Posted June 13, 2006 Share Posted June 13, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/ Share on other sites More sharing options...
Barand Posted June 13, 2006 Share Posted June 13, 2006 SOmething like thisSave 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] Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45198 Share on other sites More sharing options...
dustinto Posted June 14, 2006 Author Share Posted June 14, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45462 Share on other sites More sharing options...
crouchjay Posted June 14, 2006 Share Posted June 14, 2006 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 actionso it will look like this -> extension=php_gd2.dllinstead of -> ;extension=php_gd2.dllJay Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45486 Share on other sites More sharing options...
Barand Posted June 14, 2006 Share Posted June 14, 2006 All image functions require GD graphics extension Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45487 Share on other sites More sharing options...
dustinto Posted June 14, 2006 Author Share Posted June 14, 2006 I got that installed and it worked great. ThanksNow 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 Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45569 Share on other sites More sharing options...
Barand Posted June 14, 2006 Share Posted June 14, 2006 imagecopymerge() has a transparency argument. Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45665 Share on other sites More sharing options...
dustinto Posted June 15, 2006 Author Share Posted June 15, 2006 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 :( Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45862 Share on other sites More sharing options...
Barand Posted June 15, 2006 Share Posted June 15, 2006 imagerectangle() Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45869 Share on other sites More sharing options...
dustinto Posted June 15, 2006 Author Share Posted June 15, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45871 Share on other sites More sharing options...
Barand Posted June 15, 2006 Share Posted June 15, 2006 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'] Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45876 Share on other sites More sharing options...
dustinto Posted June 15, 2006 Author Share Posted June 15, 2006 The only problem I have now is that the imagerectangle() function needs two x , y values. Quote Link to comment https://forums.phpfreaks.com/topic/11906-image-cropping/#findComment-45887 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.