有谁知道一个PHP例程,我可以将原始图像分成两半,创建两个新图像A和B?动态分割图像
见下文:
alt text http://www.bellschofield.eu/zqocc89c.jpg
感谢
有谁知道一个PHP例程,我可以将原始图像分成两半,创建两个新图像A和B?动态分割图像
见下文:
alt text http://www.bellschofield.eu/zqocc89c.jpg
感谢
<?php
$width = 100;
$height = 100;
$source = @imagecreatefromjpeg("source.jpg");
$source_width = imagesx($source);
$source_height = imagesy($source);
for($col = 0; $col < $source_width/$width; $col++)
{
for($row = 0; $row < $source_height/$height; $row++)
{
$fn = sprintf("img%02d_%02d.jpg", $col, $row);
echo("$fn\n");
$im = @imagecreatetruecolor($width, $height);
imagecopyresized($im, $source, 0, 0,
$col * $width, $row * $height, $width, $height,
$width, $height);
imagejpeg($im, $fn);
imagedestroy($im);
}
}
?>
上面的代码从源文件获取输入:“source.jpg”。它将文件分割成100x100像素并将文件命名为img00_01.jpg等等。您可以通过更改$ height和$ width参数来更改所得图像的高度和宽度。
如何以及在哪里看到这些分割图像? – DRAJI 2014-07-09 07:22:29
阅读关于PHP GD library。你将需要如下方法:imagecreatefromjpeg()(或其他,取决于你的源文件),imagecreatetruecolor(),imagecopy(),imagejpeg()。
看看这是否有帮助http://www.phpclasses.org/package/4166-PHP-Split-large-images-in-smaller-tiles.html – Sourabh 2010-05-26 08:52:49