View Single Post
Old 05-21-2008, 03:33 PM   #14 (permalink)
j4v1
The Contributor
 
j4v1's Avatar
 
Join Date: May 2008
Posts: 30
Thanks: 5
j4v1 is on a distinguished road
Default

[quote=delayedinsanity;14731]PHP: imagecopyresized - Manual

Will do what you want, look specifically at SRC_X and SRC_Y -- you can tell it what coordinates you want to start the copy at, effectively creating a cropped area.
-m[/QUoute]
************************************************** ********
One quick question. I'm trying to do the same thing. I'd like to start my cropping from a particular area/coordinates.

Below is the sample code. Also, if you follow the link to the original gif and then in your favorite editor crop the image so that its at the following dimension 438x519 from the center. I took the following pixels (left 0, Right 119, Top 476, Bottom 204). This above result is what I'm trying to get the following code to produce.

Any assistance again you may provide would truly be appreciated.

Thank you,
j4v1

PHP Code:
<?php
cropImage
(500460'http://images.wsdot.wa.gov/nwflow/flowmaps/sysvert.gif''gif''test500x460.gif');
function 
cropImage($nw$nh$source$stype$dest) {
$size getimagesize($source);
$w $size[0];
$h $size[1];
switch(
$stype) {
case 
'gif':
$simg imagecreatefromgif($source);
break;
case 
'jpg':
$simg imagecreatefromjpeg($source);
break;
case 
'png':
$simg imagecreatefrompng($source);
break;
}
$dimg imagecreatetruecolor($nw$nh);
$wm $w/$nw;
$hm $h/$nh;
$h_height $nh/2;
$w_height $nw/2;
if(
$w $h) {
$adjusted_width $w $hm;
$half_width $adjusted_width 2;
$int_width $half_width $w_height;
imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
} elseif((
$w $h) || ($w == $h)) {
$adjusted_height $h $wm;
$half_height $adjusted_height 2;
$int_height $half_height $h_height;
imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
} else {
imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
}
imagejpeg($dimg,$dest,100);
}
?>
j4v1 is offline  
Reply With Quote