Imagemagick标题文本与一个命令中调整大小的图像顶部的阴影

时间:2016-09-07 12:22:44

标签: bash imagemagick

我正在制作一个快速的bash / imagemagick脚本

  1. 拍摄图像
  2. 裁剪并调整图像大小
  3. 将标题文字的阴影覆盖为方框
  4. 将白色标题文字叠加到相同的背面
  5. 并将其置于最终图像中。

    我可以将调整后的图像作为背景和文本的阴影放在顶部。但是,我还没有能够在阴影文本的顶部显示白色文本。

    如何在单个imagemagick命令中实现所需的输出(并且没有gimp在打开结果图像时抱怨的PNG偏移量)?

    代码:

    #!/bin/bash
    
    text="Beef meatball filet mignon, andouille biltong sausage kielbasa. Landjaeger pancetta shankle, ham hock beef corned beef kevin meatball beef ribs short ribs. Landjaeger biltong shoulder, salami brisket shank bresaola leberkas tail corned beef jowl ham pig. Venison pork loin capicola ham hock pastrami, turducken ground round prosciutto landjaeger bacon t-bone."
    
    image="abstract-waves-on-a-blue-background.jpg"
    
    width=1024
    height=768
    
    padding=100
    
    text_width=$(( $width-$padding ))
    text_height=$(( $height-$padding ))
    
    convert \
        -size "${text_width}x${text_height}" \
        -background none \
        -gravity center \
        -fill white \
        caption:"${text}" \
        -background none \
        -shadow 80x3+0+0 \
        +repage \
        \( \
        "${image}" \
        -resize "${width}x${height}^" \
        -gravity center \
        -crop "${width}x${height}+0+0" \
        \) \
        +swap \
        -gravity center \
        -composite \
        "output.png"
    

    这是我得到的输出: Bad Output 输出我想: Good Output

1 个答案:

答案 0 :(得分:1)

你非常亲密......我认为你需要这样的东西:

#!/bin/bash

text="Beef meatball filet mignon, andouille biltong sausage kielbasa. Landjaeger pancetta shankle, ham hock beef corned beef kevin meatball beef ribs short ribs. Landjaeger biltong shoulder, salami brisket shank bresaola leberkas tail corned beef jowl ham pig. Venison pork loin capicola ham hock pastrami, turducken ground round prosciutto landjaeger bacon t-bone."

image="bg.png"

width=1024
height=768

padding=100

text_width=$(( $width-$padding ))
text_height=$(( $height-$padding ))

convert \
    -size "${text_width}x${text_height}" \
    -background none \
    -gravity center \
    -fill white \
    caption:"${text}" \( +clone -shadow 80x3+0+0 \) +swap -layers merge \
    +repage \
    \( \
    "${image}" \
    -resize "${width}x${height}^" \
    -gravity center \
    -crop "${width}x${height}+0+0" \
    \) \
    +swap \
    -gravity center \
    -composite +repage \
    "output.png"