compose one transparent png(as mask) with one jpg

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
andrea70
Posts: 3
Joined: 2019-09-28T05:55:17-07:00
Authentication code: 1152

compose one transparent png(as mask) with one jpg

Post by andrea70 »

I have 2 type of images.

Some hundreds of png images with just one color(gray) and some transparent zones then must be transparent even in final result.

Over 30 thousands of jpg images with many size. I must estrapolate from jpg images the gray zones of png files.

Now i use something like this :

convert JPG_FILE.jpg -resize WIDTH_OF_PNGxHEIGHT_OF_PNG^ -gravity Center -crop WIDTH_OF_PNGxHEIGHT_OF_PNG+0+0 -alpha Set PNG_FILE.png ( -clone 0,1 -alpha Opaque -compose Hardlight -composite ) -delete 0 -compose In -composite RESULT_IMAGE.png

it works very good but its a bit slow

any suggestion for faster execution?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: compose one transparent png(as mask) with one jpg

Post by snibgo »

What version of IM, on what platform? Can you link to sample input and output images?

Perhaps your IM is Q16 HDRI but your requirement needs only Q8 non-integer.
snibgo's IM pages: im.snibgo.com
andrea70
Posts: 3
Joined: 2019-09-28T05:55:17-07:00
Authentication code: 1152

Re: compose one transparent png(as mask) with one jpg

Post by andrea70 »

i post some example not with real image, i cant .... these are not mine
but the result image dosent show pretty any Hard Light effect then i need in real application because the images are very small
the real masks(png) are around 1200x3000 px and jpg images are even bigger, this help to show lot better the little but nice Hard Light effect on the borders


jpeg example
Image
mask example
Image
result example
Image

this is what i used
convert jpeg_example.jpg -resize 300x500^ -gravity Center -crop 300x500+0+0 -alpha Set mask_example.png \( -clone 0,1 -alpha Opaque -compose Hardlight -composite \) -delete 0 -compose In -composite result.png

the blue line at end are just an error of miniatures, my images are fine :lol:
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: compose one transparent png(as mask) with one jpg

Post by magick »

We're using ImageMagick 7.0.8-66, the latest release, and HDRI is not enabled. Your command completes for us in 9 one-hundreds of a second.
andrea70
Posts: 3
Joined: 2019-09-28T05:55:17-07:00
Authentication code: 1152

Re: compose one transparent png(as mask) with one jpg

Post by andrea70 »

im on ubuntu 18.04.3 with imagemagick 6.8

wtf .... with real image i did just 1 convert every 0,41 sec at 100% cpu :?

maybe php even with shell_exec its not a good idea for mass converting :oops: , but helps me alot to keep tracking what's i have done, manage errors and so on ... even directory tree its a pain
im not an bash fan outside easy tasks :lol:

i will try something different because i have to covert too many images, at this rate i need months
Post Reply