Search code examples
imagemagickimagemagick-convert

How to change image background with watermark in imageMagick


I am trying to convert three images to one image.

pattern.png(http://tap2search.com/images/pattern.png) shirt.png(http://tap2search.com/images/shirt.png) logo.jpg(http://tap2search.com/images/logo.jpg)

convert \( -size 500x500 tile:pattern.png \) \( shirt.png -alpha extract \) -compose copy_opacity -composite png:-

The above command compose first two images(pattern.png and shirt.png) and the result is enter image description here.

But How can i put the logo.jpg as a watermark in the southeast side of the image.


Solution

  • I am not sure how you want the watermark to show. So here are 3 variations. I am using IM 6.9.10.28 Q16 Mac OSX.

    Black Watermark:

    convert \( -size 500x500 tile:pattern.png \) \
    \( shirt.png -channel a -negate +channel \
    -fill white -colorize 100 \) \
    -compose over -composite \
    \( logo.jpg -resize 50x50 \
    -negate -alpha copy \
    -fill black -colorize 100 \) \
    -gravity southeast \
    -compose over \
    -composite \
    result1.png
    


    enter image description here

    White Watermark:

    convert \( -size 500x500 tile:pattern.png \) \
    \( shirt.png -channel a -negate +channel \
    -fill white -colorize 100 \) \
    -compose over -composite \
    \( logo.jpg -resize 50x50 
    -negate -alpha copy \
    -fill white -colorize 100 \) \
    -gravity southeast \
    -compose over \
    -composite \
    result2.png
    


    enter image description here

    Partially transparent white:

    convert \( -size 500x500 tile:pattern.png \) \
    \( shirt.png -channel a -negate +channel \
    -fill white -colorize 100 \) \
    -compose over -composite \
    \( logo.jpg -resize 50x50 \
    -negate -alpha copy \
    -fill white -colorize 100 \
    -channel a -evaluate multiply 0.5 +channel \) \
    -gravity southeast \
    -compose over \
    -composite \
    result3.png
    


    enter image description here

    If you do not want the background to show through the tshirt, then do the following, for example, for the white logo.

    convert \( -size 500x500 tile:pattern.png \) \
    \( shirt.png -alpha extract -negate \
    -alpha copy \
    -channel a -threshold 0% +channel \) \
    -compose over -composite \
    \( logo.jpg -resize 50x50 \
    -negate -alpha copy \
    -fill white -colorize 100 \) \
    -gravity southeast \
    -compose over \
    -composite \
    result4.png
    


    enter image description here

    ADDITION: Regarding your new color PNG logo with transparency, try the following:

    convert \( -size 500x500 tile:pattern.png \) \
    \( shirt.png -alpha extract -negate \
    -alpha copy \
    -channel a -threshold 0% +channel \) \
    -compose over -composite \
    \( logo1.png -resize 50x50 \) \
    -gravity southeast \
    -compose over \
    -composite \
    result5.png
    


    enter image description here