Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract images from a PDF in linux while preserving transparency?

I've tried using pdfextract to extract images from a PDF and while it does extract the images I want, it extracts them with a black background. However, it also extracts a "mask" image, which I believe is the alpha channel.

enter image description here

I've read through http://www.imagemagick.org/Usage/masking, but I see no example for applying an already-extracted mask to an existing image to restore transparency. Is there a way to do this using imagemagick? If not, is there an easier way to extract images from a pdf while preserving transparency?

like image 752
Ben Davis Avatar asked Oct 28 '25 05:10

Ben Davis


1 Answers

I just found the answer from this post:

convert extracted-image.png extracted-image-mask.png -alpha off -compose copy-opacity -composite bug.png

If anyone's interested, I made a little script to do all the steps at once: https://gist.github.com/bendavis78/ed22a974c2b4534305eabb2522956359

like image 97
Ben Davis Avatar answered Oct 31 '25 11:10

Ben Davis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!