php - cropping an image
Basic way to implement a "crop" feature : given an image (src), an offset (x, y) and a size (w, h).
crop.php :
<?php
$w=$_GET['w'];
$h=isset($_GET['h'])?$_GET['h']:$w; $x=isset($_GET['x'])?$_GET['x']:0; $y=isset($_GET['y'])?$_GET['y']:0; $filename=$_GET['src'];
$image = imagecreatefromjpeg($filename);
$crop = imagecreatetruecolor($w,$h);
imagecopy ( $crop, $image, 0, 0, $x, $y, $w, $h );
imagejpeg($crop,
$filename,100
);
?>
Call it like this :
<img src="crop.php?x=10&y=20&w=30&h=40&src=photo.jpg">
No comments:
Post a Comment