2012-03-13 241 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