php - 如何使用php水平和垂直翻转图像

标签 php image flip

我在网上搜索这个,但找不到我需要的。

我有一张图片(在服务器内部或外部),我需要用 php 水平或垂直翻转图像,并像这样显示它:

<?
$img = $_GET['img'];
header('Content-type: image/png');
/*
do the flip work
*/
imagepng($img, NULL);
imagedestroy($tmp_img);
?>

我该怎么做? 谢谢大家。

最佳答案

如果您碰巧没有可用的 ImageMagick,您也可以使用 imagecopy 函数系列来实现此目的。参见 this example :

function ImageFlip ( $imgsrc, $mode )
{

    $width                        =    imagesx ( $imgsrc );
    $height                       =    imagesy ( $imgsrc );

    $src_x                        =    0;
    $src_y                        =    0;
    $src_width                    =    $width;
    $src_height                   =    $height;

    switch ( $mode )
    {

        case '1': //vertical
            $src_y                =    $height -1;
            $src_height           =    -$height;
        break;

        case '2': //horizontal
            $src_x                =    $width -1;
            $src_width            =    -$width;
        break;

        case '3': //both
            $src_x                =    $width -1;
            $src_y                =    $height -1;
            $src_width            =    -$width;
            $src_height           =    -$height;
        break;

        default:
            return $imgsrc;

    }

    $imgdest                    =    imagecreatetruecolor ( $width, $height );

    if ( imagecopyresampled ( $imgdest, $imgsrc, 0, 0, $src_x, $src_y , $width, $height, $src_width, $src_height ) )
    {
        return $imgdest;
    }

    return $imgsrc;

}

关于php - 如何使用php水平和垂直翻转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10001728/

相关文章:

python - 使用 gitbash 终端将文件从 Windows 10 移动到 ubuntu 文件夹

CSS Flip 过渡效果 - 绝对定位打破响应

php - Zend 搜索序列号(字符串而不是整数)

php - 如何通过流获取标题?

android - 在 Samsung Galaxy 设备上选择图像旋转

javascript - 简单的卡片翻转和缩放

javascript - 翻转 boolean 变量的简写

php - JavaScript注入(inject)

php - 在 INSERT (PHP) 中将 2 个不同的查询合并为一个

javascript - 图像未正确裁剪或调整大小