I have seen tons of examples of Cropping images with php & the gd lib however I have never seen any posts on Skimming or Shaving an image. What I mean by this is say you have pictures from a digital camera that places the date on picture. It is always in a constant place on the picture. So how would I do this? All examples I have come across deal with maintaining an aspect ratio which i just want those 75px or so off the bottom. how could this be done the easiest ? I found this example somewhat enlightening! imagecopyresampled in PHP, can someone explain it?
问问题
124 次
1 回答
0
要创建您需要的内容,请阅读此页面:http ://us.php.net/imagecopy
您可以使用类似的东西,只需更改 $left 和 $top 以对应于日期戳在图像上的位置。
<?php
// Original image
$filename = 'someimage.jpg';
// Get dimensions of the original image
list($current_width, $current_height) = getimagesize($filename);
// The x and y coordinates on the original image where we
// will begin cropping the image
$left = 50;
$top = 50;
// This will be the final size of the image (e.g. how many pixels
// left and down we will be going)
$crop_width = 200;
$crop_height = 200;
// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagejpeg($canvas, $filename, 100);
?>
一个类似的例子是:
实现“裁剪”功能的基本方法:给定图像 (src)、偏移量 (x, y) 和大小 (w, h)。
作物.php:
<?php
$w=$_GET['w'];
$h=isset($_GET['h'])?$_GET['h']:$w; // h est facultatif, =w par défaut
$x=isset($_GET['x'])?$_GET['x']:0; // x est facultatif, 0 par défaut
$y=isset($_GET['y'])?$_GET['y']:0; // y est facultatif, 0 par défaut
$filename=$_GET['src'];
header('Content-type: image/jpg');
header('Content-Disposition: attachment; filename='.$src);
$image = imagecreatefromjpeg($filename);
$crop = imagecreatetruecolor($w,$h);
imagecopy ( $crop, $image, 0, 0, $x, $y, $w, $h );
imagejpeg($crop);
?>
像这样称呼它:
<img src="crop.php?x=10&y=20&w=30&h=40&src=photo.jpg">
于 2010-09-14T18:11:12.947 回答