2012-03-13 239 views
4

那么我怎么能通过使用imagemagick将前图像更改为后图像? 它是-skew命令还是-distort,我怎样才能最好在typo3和php中使用它?imagemagick歪斜或扭曲图像

任何帮助表示赞赏!

before and after

+0

我想你错过了接受一个答案。例如Bonzo's - 我知道它正在工作。 – 2012-07-17 09:50:08

回答

6

使用ImageMagick用PHP和命令行:

// 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 not -distort,因为图像大于初始图像boundrys。用PHP使用我的网站上的ImageMagick的

例子http://www.rubblewebs.co.uk/imagemagick/operator.php

2

我想你要找的是什么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方法。

4

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)使用的GIFBUILDERSCALE对象应用它。例如:

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' 
    } 
    } 
} 
+0

我在Typo3中使用imageMagickExec函数尝试了失真。但是,其他像旋转一样工作时没有效果。你有什么主意吗? – netcase 2012-03-14 09:23:22

+0

通过执行我提供的第一个代码,在控制台中进行测试,即IM根据您的需要进行测试。在我测试代码时,它应该给你几乎所需的东西。如果没有,你将不得不检查你的IM安装。如果是,请测试我提供的第二个TypoScript代码。我没有测试那个。 – tmt 2012-03-14 09:36:23

+0

感谢您的帮助。我与即时通讯对抗,在旋转和其他人正在工作时仍然无法扭曲运行 – netcase 2012-03-16 11:20:09