Eran-s Posted April 12, 2006 Share Posted April 12, 2006 HI FOLKS,I NEED TO DO SOMETHING WITH IMAGES IN GD.I NEED TO CROP AN IMAGE I WILL ENTER HER ADDRESS TO A SIZE WHEN THE HEIGHT AND THE WIDTH IS SAME.THAN RESIZE IT TO 130*130 PIXELS AND THE PAGE ALSO WILL SAVE THE NEW IMAGE INTO THE SERVER IN THE PATH "IMAGES/".THANKS ALOT,ERAN. Link to comment https://forums.phpfreaks.com/topic/7216-image-croping-and-resizing/ Share on other sites More sharing options...
redarrow Posted April 12, 2006 Share Posted April 12, 2006 [!--quoteo(post=364070:date=Apr 12 2006, 03:24 PM:name=Eran-s)--][div class=\'quotetop\']QUOTE(Eran-s @ Apr 12 2006, 03:24 PM) [snapback]364070[/snapback][/div][div class=\'quotemain\'][!--quotec--]HI FOLKS,I NEED TO DO SOMETHING WITH IMAGES IN GD.I NEED TO CROP AN IMAGE I WILL ENTER HER ADDRESS TO A SIZE WHEN THE HEIGHT AND THE WIDTH IS SAME.THAN RESIZE IT TO 130*130 PIXELS AND THE PAGE ALSO WILL SAVE THE NEW IMAGE INTO THE SERVER IN THE PATH "IMAGES/".THANKS ALOT,ERAN.[/quote][a href=\"http://www.matthewkendall.com/web/php/imagefunctions/\" target=\"_blank\"]http://www.matthewkendall.com/web/php/imagefunctions/[/a]good luck. Link to comment https://forums.phpfreaks.com/topic/7216-image-croping-and-resizing/#findComment-26257 Share on other sites More sharing options...
Eran-s Posted April 12, 2006 Author Share Posted April 12, 2006 THANK YOU BUT I KNOW HOW TO RESIZE, THE MAIN PROBLEM IS TO SCALE THE SIZE TO CROP AND MAKE THE CROPPING I DON'T KNOW Link to comment https://forums.phpfreaks.com/topic/7216-image-croping-and-resizing/#findComment-26260 Share on other sites More sharing options...
redarrow Posted April 12, 2006 Share Posted April 12, 2006 [!--quoteo(post=364074:date=Apr 12 2006, 03:36 PM:name=Eran-s)--][div class=\'quotetop\']QUOTE(Eran-s @ Apr 12 2006, 03:36 PM) [snapback]364074[/snapback][/div][div class=\'quotemain\'][!--quotec--]THANK YOU BUT I KNOW HOW TO RESIZE, THE MAIN PROBLEM IS TO SCALE THE SIZE TO CROP AND MAKE THE CROPPING I DON'T KNOW[/quote]There you go an easy example ok.[code]<?php02 03 // the image to crop04 $image = 'pics/whatever.jpg';05 // make sure the directory is writeable06 $dest_image = 'pics/cropped_whatever.jpg';07 08 // to keep the image and layer in sync09 $margin = 10;10 11 if(!isset($_POST['step'])) $title = '1';12 else $title = $_POST['step'];13 14 echo '15 <html>16 <head>17 <title>lixlpixel image crop | step '.$title.'</title>18 </head>19 <body style="margin: '.$margin.'px;">';20 21 if(!isset($_POST['tx']) && !isset($_POST['fx']))22 {23 echo '24 <form method="post" action="'.$_SERVER['PHP_SELF'].'">25 <input type="image" src="'.$image.'" /><br />';26 if(!isset($_POST['x']))27 {28 echo '29 <input type="hidden" name="step" value="2" />30 click to mark first corner';31 }else{32 echo '33 <input type="hidden" name="step" value="3" />34 <input type="hidden" name="fx" value="'.$_POST['x'].'" />35 <input type="hidden" name="fy" value="'.$_POST['y'].'" />36 click to mark second corner | <a href="'.$_SERVER['PHP_SELF'].'">start over</a>';37 }38 echo '39 </form>40 ';41 }42 43 if(isset($_POST['fx']))44 {45 echo '46 <form method="post" action="'.$_SERVER['PHP_SELF'].'">47 <input type="hidden" name="step" value="4" />48 <input type="image" src="'.$image.'" /><br />49 <input type="hidden" name="tx" value="'.$_POST['fx'].'" />50 <input type="hidden" name="ty" value="'.$_POST['fy'].'" />51 <input type="hidden" name="width" value="'.($_POST['x']-$_POST['fx']).'" />52 <input type="hidden" name="height" value="'.($_POST['y']-$_POST['fy']).'" />53 <div style="position: absolute;54 left:'.($_POST['fx']+$margin).'px;55 top: '.($_POST['fy']+$margin).'px;56 width: '.($_POST['x']-$_POST['fx']).'px;57 height: '.($_POST['y']-$_POST['fy']).'px;58 border: 1px solid #fff;">59 </div>60 click image to crop rectangle | <a href="'.$_SERVER['PHP_SELF'].'">start over</a>61 </form>';62 }63 64 if(isset($_POST['tx']))65 {66 $img = imagecreatetruecolor($_POST['width'],$_POST['height']);67 $org_img = imagecreatefromjpeg($image);68 $ims = getimagesize($image);69 imagecopy($img,$org_img, 0, 0, $_POST['tx'], $_POST['ty'], $ims[0], $ims[1]);70 imagejpeg($img,$dest_image,90);71 imagedestroy($img);72 echo '73 <img src="'.$dest_image.'" 74 width="'.$_POST['width'].'" 75 height="'.$_POST['height'].'" alt="" /><br />76 <a href="'.$_SERVER['PHP_SELF'].'">try again</a>';77 }78 79 echo '80 </body>81 </html>';82 83 ?>[/code] Link to comment https://forums.phpfreaks.com/topic/7216-image-croping-and-resizing/#findComment-26263 Share on other sites More sharing options...
Eran-s Posted April 12, 2006 Author Share Posted April 12, 2006 THANK YOU, I WILL TRY TO USE IT TO MY OWN NEEDS. Link to comment https://forums.phpfreaks.com/topic/7216-image-croping-and-resizing/#findComment-26272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.