动态拆分图像

Oli*_*ver 1 php image-processing

有没有人知道一个PHP例程,我可以拍摄原始图像并将其分成两半以创建两个新图像A和B?

见下文:

alt text http://www.bellschofield.eu/zqocc89c.jpg

谢谢

小智 11

<?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 );
        }
    } 
    ?>
Run Code Online (Sandbox Code Playgroud)

上面的代码从源文件中获取输入:"source.jpg".它将文件分成100x100像素并命名文件img00_01.jpg等等....您可以通过更改$ height和$ width参数来更改结果图像的高度和宽度.