imageflip

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

imageflipBelirtilen kipi kullanarak görüntüyü ters çevirir

Açıklama

imageflip(GdImage $görüntü, int $kip): bool

Belirtilen kipe göre görüntüyü ters çevirir.

Bağımsız Değişkenler

görüntü

imagecreatetruecolor() gibi bir görüntü oluşturma işlevinden dönen bir GdImage nesnesi.

kip

Görüntünün nasıl ters çevrileceği aşağıdaki IMG_FLIP_* sabitleri ile belirtilir:

Sabit Anlamı
IMG_FLIP_HORIZONTAL Resim yatay olarak ters çevrilir.
IMG_FLIP_VERTICAL Resim dikey olarak ters çevrilir.
IMG_FLIP_BOTH Resim hem dikey hem de yatay olarak ters çevrilir.

Dönen Değerler

Başarı durumunda true, başarısızlık durumunda false döner.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0 görüntü bağımsız değişkeninde artık bir GdImage nesnesi aktarmak gerekiyor; evvelce resource türünde geçerli bir gd değeri gerekirdi.

Örnekler

Örnek 1 - Görüntüyü dikey olarak ters çevirmek

Bu örnekte IMG_FLIP_VERTICAL sabiti kullanılmıştır.

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

// İçerik türü
header('Content-Type: image/png');

// Yükle
$im = imagecreatefrompng($filename);

// Düşey olarak tersine çevir
imageflip($im, IMG_FLIP_VERTICAL);

// Çıktıla
imagejpeg($im);
imagedestroy($im);
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

Örnek çıktısı: Düşeyde ters çevrilmiş görüntü

Örnek 2 - Görüntüyü yatay olarak ters çevirmek

Bu örnekte IMG_FLIP_HORIZONTAL sabiti kullanılmıştır.

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

// İçerik türü
header('Content-Type: image/png');

// Yükle
$im = imagecreatefrompng($filename);

// Yatayda tersine çevir
imageflip($im, IMG_FLIP_HORIZONTAL);

// Çıktıla
imagejpeg($im);
imagedestroy($im);
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

Örnek çıktısı: Yatayda ters çevrilmiş görüntü

add a note

User Contributed Notes 1 note

up
4
Daniel Klein
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.<?phpif (!function_exists('imageflip')) {  define('IMG_FLIP_HORIZONTAL', 0);  define('IMG_FLIP_VERTICAL', 1);  define('IMG_FLIP_BOTH', 2);  function imageflip($image, $mode) {    switch ($mode) {      case IMG_FLIP_HORIZONTAL: {        $max_x = imagesx($image) - 1;        $half_x = $max_x / 2;        $sy = imagesy($image);        $temp_image = imageistruecolor($image)? imagecreatetruecolor(1, $sy): imagecreate(1, $sy);        for ($x = 0; $x < $half_x; ++$x) {          imagecopy($temp_image, $image, 0, 0, $x, 0, 1, $sy);          imagecopy($image, $image, $x, 0, $max_x - $x, 0, 1, $sy);          imagecopy($image, $temp_image, $max_x - $x, 0, 0, 0, 1, $sy);        }        break;      }      case IMG_FLIP_VERTICAL: {        $sx = imagesx($image);        $max_y = imagesy($image) - 1;        $half_y = $max_y / 2;        $temp_image = imageistruecolor($image)? imagecreatetruecolor($sx, 1): imagecreate($sx, 1);        for ($y = 0; $y < $half_y; ++$y) {          imagecopy($temp_image, $image, 0, 0, 0, $y, $sx, 1);          imagecopy($image, $image, 0, $y, 0, $max_y - $y, $sx, 1);          imagecopy($image, $temp_image, 0, $max_y - $y, 0, 0, $sx, 1);        }        break;      }      case IMG_FLIP_BOTH: {        $sx = imagesx($image);        $sy = imagesy($image);        $temp_image = imagerotate($image, 180, 0);        imagecopy($image, $temp_image, 0, 0, 0, 0, $sx, $sy);        break;      }      default: {        return;      }    }    imagedestroy($temp_image);  }}?>
To Top