【问题标题】:imagemagick skew or distort an imageimagemagick 歪斜或扭曲图像
【发布时间】:2012-03-30 00:25:03
【问题描述】:

我如何使用 imagemagick 将前图像更改为后图像? 是-skew命令还是-distort,如何在typo3和php中更好地使用?

感谢任何帮助!

【问题讨论】:

  • 我认为您错过了接受答案。例如 Bonzo 的 -- 我知道它正在工作。

标签: php imagemagick typo3


【解决方案1】:

在 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 示例

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 我用 Typo3 中的 imageMagickExec 函数尝试了失真。但是当旋转等其他人正在工作时没有效果。你有什么想法吗?
    • 在控制台中测试 IM 通过执行我提供的第一个代码来执行您想要的操作。当我测试代码时,它应该会给你几乎你想要的东西。如果没有,您将不得不检查您的 IM 安装。如果是,请测试我提供的第二个 TypoScript 代码。不过我没有测试那个。
    • 感谢您的帮助。我正在与 IM 作斗争,但在旋转和其他人工作时仍然无法扭曲运行
    【解决方案3】:

    我认为您正在寻找的是 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 方法。

    【讨论】:

      猜你喜欢
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      相关资源
      最近更新 更多