【问题标题】:Chop 4 sides of image with Imagemagick用 Imagemagick 剪掉图像的 4 面
【发布时间】:2018-11-02 19:45:39
【问题描述】:

我有以下图片:

test PNG 1366x655 1366x655+0+0 8-bit sRGB 286KB 0.000u 0:00.000

我需要像这样从图像的边框切掉它:

top: 140 px
bottom: 140 px
left: 180 px
right: 60 px

是否有使用convert 执行此操作的单行命令行?

【问题讨论】:

  • 恭喜 SO bash 问题编号 100,000!
  • 哇!谢谢老兄=D

标签: bash shell image-processing imagemagick imagemagick-convert


【解决方案1】:

你可以合并两个-crops:

                      #left,top      right,bottom
convert test.png -crop +180+140 -crop -60-140 cropped.png

【讨论】:

  • 很好的解决方案,它工作得很好,谢谢!只是指出它应该是convert test.png -crop +180+140 -crop -60-140 cropped.png 考虑到左边(+180 px),顶部(+140 px),右边(-60 px ) 和底部 (-140 像素) 方向。再次感谢。
【解决方案2】:

that other guy 的解决方案非常聪明。标准方法是使用 -chop。但这意味着 4 次调用,因为要删除的大小没有对称性。所以在 ImageMagick 中使用 -chop,你可以这样做

convert text.png -gravity north -chop 0x180 -gravity east -chop 60x0 -gravity south -chop 0x140 -gravity west -chop 140x0 cropped.png

http://www.imagemagick.org/Usage/crop/#chop

当左/右或上/下或四周对称时,另请参阅 -shave。 http://www.imagemagick.org/Usage/crop/#shave

【讨论】:

    【解决方案3】:

    使用 V7 的另一种方法

    魔术输入 -crop "%[fx:w-(180+60)]"x"%[fx:h-(140+140)]"+180+140 结果

    【讨论】:

      【解决方案4】:

      基于 Bonzo 的解决方案,您可以在 ImageMagick 6 中使用视口裁剪(Unix 语法)做类似的事情:

      top=140
      bottom=140
      left=180
      right=60
      convert image.png -set option:distort:viewport "%[fx:w-$left-$right]x%[fx:h-$top-$bottom]+${left}+${top}" -filter point +distort SRT 0 +repage result.png
      

      【讨论】:

        猜你喜欢
        • 2013-04-05
        • 2012-05-19
        • 2013-08-06
        • 2017-03-21
        • 2018-07-15
        • 1970-01-01
        • 2019-06-04
        • 2011-06-16
        • 1970-01-01
        相关资源
        最近更新 更多