0

php と gd lib を使用した画像のトリミングの例をたくさん見てきましたが、画像のスキミングやシェービングに関する投稿は見たことがありません。これが意味することは、写真に日付を配置するデジタル カメラからの写真があるとします。それは常に絵の一定の場所にあります。では、どうすればよいでしょうか?私が遭遇したすべての例は、縦横比を維持することに対処しており、75px程度を下から離したいだけです。これを最も簡単に行うにはどうすればよいでしょうか。この例はやや啓発的であることがわかりました。 PHPでimagecopyresampled、誰か説明できますか?

4

1 に答える 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)を指定します。

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">
于 2010-09-14T18:11:12.947 に答える