Skip to main content
Added another example that'll work
Source Link
emcconville
  • 24.4k
  • 4
  • 51
  • 66

Many different techniques can be used. ImageMagick has FX language that can perform complex calculations.

convert a.jpg b.jpg -fx 'Wi=w/2; Hi=h/2; hypot(Wi-i, Hi-j) < 50 ? u : v' c.jpg

For example...

convert -size 100x100 PLASMA: a.jpg

a.jpg

convert -size 100x100 GRADIENT:LIME-ORANGE b.jpg

b.jpg

convert a.jpg b.jpg -fx 'hypot(50-i, 50-j) < 50 ? u : v' c.jpg

c.jpg

Update with another technique.

A faster approach can be leveraging image mask(s) of the shape you wish to crop, and compose/composite it between both images. It'll require a format that supports alpha channels, but only for the initial work. For example...

Create a circle mask, and copy values to alpha channel.

convert -size 100x100 xc:White -fill Black \
        -draw 'circle 50 50 50 5' -alpha Copy mask.png

mask.png

convert \( a.png mask.png -alpha Set -compose Dst_Out -composite \) \
        b.png -compose Dst_Atop -composite c.png

c.png

Many different techniques can be used. ImageMagick has FX language that can perform complex calculations.

convert a.jpg b.jpg -fx 'Wi=w/2; Hi=h/2; hypot(Wi-i, Hi-j) < 50 ? u : v' c.jpg

For example...

convert -size 100x100 PLASMA: a.jpg

a.jpg

convert -size 100x100 GRADIENT:LIME-ORANGE b.jpg

b.jpg

convert a.jpg b.jpg -fx 'hypot(50-i, 50-j) < 50 ? u : v' c.jpg

c.jpg

Many different techniques can be used. ImageMagick has FX language that can perform complex calculations.

convert a.jpg b.jpg -fx 'Wi=w/2; Hi=h/2; hypot(Wi-i, Hi-j) < 50 ? u : v' c.jpg

For example...

convert -size 100x100 PLASMA: a.jpg

a.jpg

convert -size 100x100 GRADIENT:LIME-ORANGE b.jpg

b.jpg

convert a.jpg b.jpg -fx 'hypot(50-i, 50-j) < 50 ? u : v' c.jpg

c.jpg

Update with another technique.

A faster approach can be leveraging image mask(s) of the shape you wish to crop, and compose/composite it between both images. It'll require a format that supports alpha channels, but only for the initial work. For example...

Create a circle mask, and copy values to alpha channel.

convert -size 100x100 xc:White -fill Black \
        -draw 'circle 50 50 50 5' -alpha Copy mask.png

mask.png

convert \( a.png mask.png -alpha Set -compose Dst_Out -composite \) \
        b.png -compose Dst_Atop -composite c.png

c.png

Added examples
Source Link
emcconville
  • 24.4k
  • 4
  • 51
  • 66

Many different techniques can be used. ImageMagick has FX language that can perform complex calculations.

convert a.jpg b.jpg -fx 'Wi=w/2; Hi=h/2; hypot(Wi-i, Hi-j) < 50 ? u : v' c.jpg

For example...

convert -size 100x100 PLASMA: a.jpg

a.jpg

convert -size 100x100 GRADIENT:LIME-ORANGE b.jpg

b.jpg

convert a.jpg b.jpg -fx 'hypot(50-i, 50-j) < 50 ? u : v' c.jpg

c.jpg

Many different techniques can be used. ImageMagick has FX language that can perform complex calculations.

convert a.jpg b.jpg -fx 'Wi=w/2; Hi=h/2; hypot(Wi-i, Hi-j) < 50 ? u : v' c.jpg

Many different techniques can be used. ImageMagick has FX language that can perform complex calculations.

convert a.jpg b.jpg -fx 'Wi=w/2; Hi=h/2; hypot(Wi-i, Hi-j) < 50 ? u : v' c.jpg

For example...

convert -size 100x100 PLASMA: a.jpg

a.jpg

convert -size 100x100 GRADIENT:LIME-ORANGE b.jpg

b.jpg

convert a.jpg b.jpg -fx 'hypot(50-i, 50-j) < 50 ? u : v' c.jpg

c.jpg

Source Link
emcconville
  • 24.4k
  • 4
  • 51
  • 66

Many different techniques can be used. ImageMagick has FX language that can perform complex calculations.

convert a.jpg b.jpg -fx 'Wi=w/2; Hi=h/2; hypot(Wi-i, Hi-j) < 50 ? u : v' c.jpg