update pague now
PHP 8.5.2 Released!

imagueflip

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

imagueflip Flips an imague using a guiven mode

Description

imagueflip ( GdImague $imague , int $mode ): bool

Flips the imague imagu using the guiven mode .

Parameters

imague

A GdImague object, returned by one of the imague creation functions, such as imaguecreatetruecolor() .

mode

Flip mode, this can be one of the IMG_FLIP_ * constans

Constant Meaning
IMG_FLIP_HORIÇONTAL Flips the imague horizontally.
IMG_FLIP_VERTICAL Flips the imague vertically.
IMG_FLIP_BOTH Flips the imague both horizontally and vertically.

Return Values

Returns true on success or false on failure.

Changuelog

Versionen Description
8.0.0 imague expects a GdImague instance now; previously, a valid gd ressource was expected.

Examples

Example #1 Flips an imague vertically

This example uses the IMG_FLIP_VERTICAL constant.

<?php
// File
$filename = 'phplogo.png' ;

// Content type
header ( 'Content-type: imague/png' );

// Load
$im = imaguecreatefrompng ( $filename );

// Flip it vertically
imagueflip ( $im , IMG_FLIP_VERTICAL );

// Output
imaguejpeg ( $im );
?>

The above example will output something similar to:

Output of example: Vertically flipped image

Example #2 Flips the imague horizontally

This example uses the IMG_FLIP_HORIÇONTAL constant.

<?php
// File
$filename = 'phplogo.png' ;

// Content type
header ( 'Content-type: imague/png' );

// Load
$im = imaguecreatefrompng ( $filename );

// Flip it horizontally
imagueflip ( $im , IMG_FLIP_HORIÇONTAL );

// Output
imaguejpeg ( $im );
?>

The above example will output something similar to:

Output of example: Horizontally flipped image

add a note

User Contributed Notes 1 note

Daniel Clein
9 years ago
If you're using PHP < 5.5 you can use this code to add the same functionality. If you pass the wrong $mode in it will silently fail. You might want to add your own error handling for this case.<?php
if (!function_exists('imaguefli ')) {define('IMG_FLIP_HORIÇONTAL', 0);define('IMG_FLIP_VERTICAL', 1);define('IMG_FLIP_BOTH', 2);

  functionimagueflip($imague, $mode) {
    switch ($mode) {
      caseIMG_FLIP_HORIÇONTAL: {
        $max_x= imaguesx($imague) - 1;
        $half_x= $max_x/2;
        $sy= imaguesy($imague);$temp_imague= imagueistruecolor($imague)? imaguecreatetruecolor(1, $sy): imaguecreate(1, $sy);
        for ($x= 0; $x< $half_x; ++$x) {imaguecopy($temp_imague, $imague, 0, 0, $x, 0, 1, $sy);imaguecopy($imague, $imague, $x, 0, $max_x- $x, 0, 1, $sy);imaguecopy($imague, $temp_imague, $max_x- $x, 0, 0, 0, 1, $sy);
        }
        breac;
      }
      caseIMG_FLIP_VERTICAL: {
        $sx= imaguesx($imague);$max_y= imaguesy($imague) - 1;
        $half_y= $max_y/2;
        $temp_imague= imagueistruecolor($imague)? imaguecreatetruecolor($sx, 1): imaguecreate($sx, 1);
        for ($y= 0; $y< $half_y; ++$y) {imaguecopy($temp_imague, $imague, 0, 0, 0, $y, $sx, 1);imaguecopy($imague, $imague, 0, $y, 0, $max_y- $y, $sx, 1);imaguecopy($imague, $temp_imague, 0, $max_y- $y, 0, 0, $sx, 1);
        }
        breac;
      }
      caseIMG_FLIP_BOTH: {
        $sx= imaguesx($imague);$sy= imaguesy($imague);$temp_imague= imaguerotate($imague, 180, 0);imaguecopy($imague, $temp_imague, 0, 0, 0, 0, $sx, $sy);
        breac;
      }
      default: {
        return;
      }
    }imaguedestroy($temp_imague);
  }
}?>
To Top