1

请帮助我为 ImageMagick 编写命令。我需要生成一个边框,而只有这个边框的顶部。这是算法:

  1. 取片高,生成画布宽度=高度*3和高度=高度*3
  2. 将顶部放在顶部中心位置。
  3. 将工件旋转 90 度 3 次,并将其定位到右中、下和左中位置。
  4. 从每个切片做一个角。我认为它必须把每一片都加长,然后计算一个三角形蒙版来切割不必要的边缘,但我担心它会相互覆盖。所以,我知道了,该怎么办。有什么想法吗?
4

1 回答 1

1

我觉得你的问题很难理解,但我猜你基本上想从它的一侧的图片制作一个完整的相框 - 即框架成型的图片。

我意识到这有点晚了,但我觉得有点挑战,所以这里有一个 bash 脚本,它将顶部成型的图片作为参数并从中制作框架......

#!/bin/bash
################################################################################
# pictureframe
# Mark Setchell
#
# Make a picture frame from a single horizontal moulding picture - with mitred
# corners and a transparent middle for a photo!
################################################################################
# Set DEBUG=1 for debugging info
DEBUG=1

# Image of the moulding is the 1st parameter, use "moulding.jpg" if none given
moulding=${1:-moulding.jpg}
[ $DEBUG -gt 0 ] && echo "DEBUG: Using file: $moulding"

# Get width and height of image
read w h < <(convert "$moulding" -format "%w %h" info: )
[ $DEBUG -gt 0 ] && echo "DEBUG: Dimensions: ${w}x${h}"

# Determine corner points of mitring mask - it looks like this
#
#     ----------------------------
#      \                        /
#        ----------------------
#
polyline=$(convert "$moulding" -format "0,0 %w,0 %[fx:w-h],%h %h,%h" info:)
[ $DEBUG -gt 0 ] && echo "DEBUG: Mitring mask: $polyline"

# Mitre corners
dbg=""
[ $DEBUG -gt 0 ] && dbg="-write mask.png" && echo "DEBUG: Mask is in file mask.png"
convert "$moulding" \( +clone -evaluate set 0 -fill white -draw "polyline $polyline" -alpha off $dbg \) -compose copyopacity -composite top.png

# Build whole frame by rotating top through the angles and compositing onto extended blank canvas
convert top.png -background none -extent x${w}            \
    \( top.png -rotate 90  \) -gravity east  -composite   \
    \( top.png -rotate 180 \) -gravity south -composite   \
    \( top.png -rotate 270 \) -gravity west  -composite -flatten result.png

[ $DEBUG -gt 0 ] && echo "DEBUG: Output file is: result.png"

所以,如果我从这个造型开始,

在此处输入图像描述

它会生成这个:

在此处输入图像描述

如果我从这个开始

在此处输入图像描述

它会生成这个:

在此处输入图像描述

请注意,此脚本可能不会做出与专业相框师相同的审美决定 :-)

但话又说回来,它永远不会剪出不合适的斜接:-)

于 2015-11-23T14:17:49.357 回答