Im trying to convert a PDF or JPG file into a png with specific colors being transparent.
For example. I have a file with white background and black text and would like to convert the white area to be transparent on the png
I have tried using imagemagick :
exec('convert -density 144 ' . $infile.' -transparent "#FFFFFF" ' .$png_file);
and this seems to work at times and not other times for some reason
also the edges of the black come out kind of jagged. Does anyone know of a way to make the edges smoother. or any other function in php to use to create the transparency.
Also the quality needs to be perfect as well as sometimes when the dimensions of the file are small the output png is very low res and i need to keep it at the same dimensions so i cant really use the -density function
You can overcome the jagged edges using the fuzz factor option -fuzz
, but as the usage manual explains, the results may or may not fit your needs.
Background removal is also discussed at length in the usage manual , describing several techniques besides using the -transparent
option.
Without more information, I don't know why your conversion code works sometimes and not at others, but I don't think you need the -density
option for JPG conversion. That might be the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.