我在网上搜索这个,我找不到我需要的东西.
我有一个图像(服务器内部或外部),我需要使用PHP水平或垂直翻转图像,并显示如下:
<?
$img = $_GET['img'];
header('Content-type: image/png');
/*
do the flip work
*/
imagepng($img, NULL);
imagedestroy($tmp_img);
?>
Run Code Online (Sandbox Code Playgroud)
我该怎么做?谢谢你们.
Jon*_*ant 10
imagecopy
如果您没有使用ImageMagick,也可以使用函数系列实现此功能.看这个例子:
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;
}
Run Code Online (Sandbox Code Playgroud)
使用ImageMagick和flipImage()
and flopImage()
方法,以下示例来自devzone.zend.com:
<?php
try {
// initialize object
$image = new Gmagick();
// read image file
$image->readImage('gallery/original.jpg');
// flip image vertically
$image->flipImage();
// write new image file
$image->writeImage('gallery/new_1.jpg');
// revert
$image->flipImage();
// flip image horizontally
$image->flopImage();
// write new image file
$image->writeImage('gallery/new_2.jpg');
// free resource handle
$image->destroy();
} catch (Exception $e) {
die ($e->getMessage());
}
?>
Run Code Online (Sandbox Code Playgroud)
结果如下:
归档时间: |
|
查看次数: |
8684 次 |
最近记录: |