【发布时间】:2012-03-30 00:25:03
【问题描述】:
我如何使用 imagemagick 将前图像更改为后图像? 是-skew命令还是-distort,如何在typo3和php中更好地使用?
感谢任何帮助!
【问题讨论】:
-
我认为您错过了接受答案。例如 Bonzo 的 -- 我知道它正在工作。
标签: php imagemagick typo3
我如何使用 imagemagick 将前图像更改为后图像? 是-skew命令还是-distort,如何在typo3和php中更好地使用?
感谢任何帮助!
【问题讨论】:
标签: php imagemagick typo3
在 php 和命令行中使用 Imagemagick:
// Working on the original image size of 400 x 300
$cmd = "before.jpg -matte -virtual-pixel transparent".
" +distort Perspective \"0,0 0,0 400,0 400,22 400,300 400,320 0,300 0,300 \" ";
exec("convert $cmd perspective.png");
注意: 1/ 这适用于 Imagemagick 的更高版本 - 透视运算符已更改。 2/你需要使用+distort而不是-distort,因为图像大于初始图像边界。
在我的网站http://www.rubblewebs.co.uk/imagemagick/operator.php上使用 php 的 Imagemagick 示例
【讨论】:
Perspective distortion 应该给你你想要的。示例:
convert original.png -matte -virtual-pixel white +distort Perspective '0,0,0,0 0,100,0,100 100,100,90,110 100,0,90,5' distorted.png
在 TYPO3 中,您可以通过 (ab) 使用 GIFBUILDER 的 SCALE 对象来应用它。示例:
temp.example = IMAGE
temp.example {
file = GIFBUILDER
file {
format = jpg
quality = 100
maxWidth = 9999
maxHeight = 9999
XY = [10.w],[10.h]
10 = IMAGE
10.file = fileadmin/original.png
20 = SCALE
20 {
params = -matte -virtual-pixel white +distort Perspective '0,0,0,0 0,100,0,100 100,100,90,110 100,0,90,5'
}
}
}
【讨论】:
我认为您正在寻找的是 Imagick::shearImage 函数。这会创建一个棋盘正方形并将其扭曲为平行四边形(将其保存为 PHP 文件并在浏览器中打开查看):
<?php
$im = new Imagick();
$im->newPseudoImage(300, 300, "pattern:checkerboard");
$im->setImageFormat('png');
$im->shearImage("transparent", 0, 10);
header("Content-Type: image/png");
echo $im;
?>
在较大的脚本中,要剪切名为 myimg.png 的图像并将其保存为 myimg-sheared.png,您可以使用:
$im = new Imagick("myimg.png");
$im->shearImage("transparent", 0, 10);
$im->writeImage("myimg_sheared.png");
如果shearImage 不够通用,您可以通过Imagick::distortImage 函数尝试Imagick::DISTORTION_PERSPECTIVE 方法。
【讨论】: