我在网上搜索这个,但找不到我需要的。
我有一张图片(在服务器内部或外部),我需要用 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/