how to divide image into three equal parts in php imagemagick and combine with some padding and output as single image

前端 未结 2 1854
生来不讨喜
生来不讨喜 2021-01-24 06:59

I want to display an image into three parts as triptych with the help of imagemagick PHP library. I saw the same example here

http://www.rubbleimages.com/Canvas.php.

相关标签:
2条回答
  • 2021-01-24 07:44

    I am hopeless at PHP but something like this seems to work for me:

    #!/usr/local/bin/php -f
    <?php
    
       $padding=10;
       $info = getimagesize("input.jpg");
       $width=$info[0];
       $height=$info[1];
    
       // Calculate dimensions of output image
       $canvasWidth=$width+4*$padding;
       $canvasHeight=$height+2*$padding;
    
       // create white canvas
       $output = imagecreatetruecolor($canvasWidth, $canvasHeight);
       $background = imagecolorallocate($output, 255, 255, 255);
       imagefill($output, 0, 0, $background);
    
       // read in original image
       $orig = imagecreatefromjpeg("input.jpg");
    
       // copy left third to output image
       imagecopy($output, $orig,$padding,             $padding,             0, 0, $width/3, $height);
       // copy central third to output image
       imagecopy($output, $orig,2*$padding+$width/3,  $padding,      $width/3, 0, $width/3, $height);
       // copy right third to output image
       imagecopy($output, $orig,3*$padding+2*$width/3,$padding,    2*$width/3, 0, $width/3, $height);
    
       // save output image
       imagejpeg($output,"result.jpg");
    ?>
    

    If I start with this:

    enter image description here

    I get this as a result

    enter image description here

    I added the black outline afterwards so you can see the extent of the image.

    0 讨论(0)
  • 2021-01-24 07:46
    $cmd = " convert $photo  -crop 33.5%x100%  +repage  -raise 5x1      "."    monet_horizontal_%d.jpg";
    
    exec($cmd);
    
    $cmd = " convert monet_horizontal_0.jpg wt.png monet_horizontal_1.jpg wt.png monet_horizontal_2.jpg  +append "."  abc.jpg";
    
    exec($cmd);
    
    0 讨论(0)
提交回复
热议问题