2010-09-14 77 views
0

我已经看到了很多使用php剪下图像的例子& gd lib但是我从来没有在Skimming或Shaving图像上看到任何帖子。我的意思是说,你有一张数码相机的照片,将日期放在照片上。它总是在图片上不变的地方。那么我会如何做到这一点?我遇到的所有例子都涉及维持一个纵横比,我只是希望那些75px左右的底部。这怎么能做到最简单?我发现这个例子有点启发! imagecopyresampled in PHP, can someone explain it?使用php浏览图像& gd;

回答

0

创造什么样的,你只需要阅读此页:http://us.php.net/imagecopy

您可以使用这样的事情,只是改变$左侧和顶部$对应于其中的日期戳在图像上。

<?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):

实施 “作物” 功能基本方式。

crop.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"> 
+0

确定日期和时间标记总是在右下角所以在你的例子我应该这样做$脱脂= 75 ; $ left = 0; $ top = 0; (从左上角开始到最上面0位置),然后$ crop_width = imagesx($ file); $ crop_height =(imagesy($ file) - $ skim);就像我之前说过的,我并没有试图用200x200 w/h的比例缩小它,也没有试图保持任何方面,因为整个图像上的Skimming 75px甚至没有被看到 – dominicdinada 2010-09-14 20:14:30

+0

Imagecopy不工作,它只是用黑色空间填充相同的图像在应该裁剪的区域。但它让我在我提供的链接上看起来更加接近。 – dominicdinada 2010-09-14 21:34:16