Search code examples
phpimagegdimage-manipulation

PHP GD imagecopyresampled() and flip it horizontal


I'm rendering a PNG image from another PNG image with imagecopyresampled(). Now i want some parts of the image to be flipped horizontal, so i have tried this:

//horizontal
$src_x     = $width - 1;
$src_width = -$width;

imagecopyresampled(
    $imgdest, $imgsrc, 0, 0, $src_x, $src_y , $width, $height
    , $src_width, $src_height
);

Taken from a user-comment from the PHP Manual.

It does not work in my case (where I copy a lot of pieces from the original image to the new), instead it copies another piece of the image. Does anyone has a solution to this?


Solution

  • Okay so many years after I found the answer myself, so I just wanted to let anybody else know.

    It was pretty simple, example:

    Instead of:

    imagecopy($output, $input, 8, 20, 4, 20, 4, 12)
    

    I would use:

    imagecopyresampled($output, $input, 8, 20, (8 - 1), 20, 4, 12, 0 - 4, 12);
    

    Which would flip the part of the image horizontal.