Graphics
|
|
|
|
<? //
// image crop fuction ..... Duck@obala.net
//
// $cropX = source starting X
// $cropY = source starting Y
// $cropW = crom weigth
// $cropH = crom heigh
// $source = source filename
// $desctination = desctination filename
// $type = image type
function im_crop($cropX,$cropY,$cropH,$cropW,$source,$destination,$type='jpeg') {
switch ($type) {
case 'wbmp': $sim = ImageCreateFromWBMP($source); break;
case 'gif': $sim = ImageCreateFromGIF($source); break;
case 'png': $sim = ImageCreateFromPNG($source); break;
default: $sim = ImageCreateFromJPEG($source); break;
}
$dim = imagecreate($cropW, $cropH);
for ( $i=$cropY; $i<($cropY+$cropH); $i++ ) {
for ( $j=$cropX; $j<($cropX+$cropW); $j++ ) {
$color = imagecolorsforindex($sim, imagecolorat($sim, $j, $i));
$index = ImageColorAllocate($dim, $color['red'], $color['green'], $color['blue']);
imagesetpixel($dim, $j-$cropX, $i-$cropY, $index);
}
}
imagedestroy($sim);
switch ($type) {
case 'wbmp': ImageWBMP($dim, $destination); break;
case 'gif': ImageGIF($dim, $destination); break;
case 'png': ImagePNG($dim, $destination); break;
default: ImageJPEG($dim, $destination); break;
}
imagedestroy($dim);
} ?>
|
|
|
Usage Example
|
|
|
Rate This Script
|
|
|
|