【问题标题】:Add white rectangle to bottom of image with imageMagick in R使用R中的imageMagick将白色矩形添加到图像底部
【发布时间】:2020-11-04 14:03:48
【问题描述】:

我希望使用 R 的 magick 库在 .png 图像的底部添加一个白色矩形。

白色矩形的尺寸

宽度:1200px

高度:50px

我认为 append 会很有用。然而,我不清楚如何创建而不是阅读,一个白色的矩形图像。具体来说,如何在这个高度为 50px 且与图像长度一致的汽车图像底部添加一个白色矩形。

library("magick")
url <- "https://images.unsplash.com/photo-1604397707219-dfe825b8a59d"
 

【问题讨论】:

  • 在命令行中将是convert -size 1200x50 xc:white white_rectangle.png 希望对您有所帮助。抱歉,我不知道 R 的魔法语法。注意 xc:white 可以用 canvas:white 代替。

标签: r imagemagick


【解决方案1】:

使用image_blank 创建白色矩形。然后使用image_composite 组合图像。

library(magick)
url <- "https://images.unsplash.com/photo-1604397707219-dfe825b8a59d"

img <- image_read(url)
white <- image_blank(1200, 50, "white")

x <- image_info(img)$width - 1200
y <- image_info(img)$height - 50

image_composite(img, white, offset = paste0("+", x, "+", y))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多