Why, when you convert in ImageMagick from PNG to JPG get black picture?

Debian OS 9, a utility ImageMagick.

Convert: convert file.png file.jpg
the conversion takes place without problems, but some pictures, when you convert get a completely black picture.

Where to take the files that problem:
in MS Word save document in pdf format
Open it in Photoshop and save to png

The problematic png files normally open. If you convert to webp, too, no problem:
/usr/bin/cwebp -q 75-m 6 aaa.png -o $aaa.webp

Why get a black image when converting PNG -> JPEG, and how to overcome?
March 23rd 20 at 18:50
2 answers
March 23rd 20 at 18:52
First, don't bother and save from Photoshop with transparency. Second, imagemagick is the key background to set the background color. Third, it is unclear why save the black-and-white images in the JPEG to PNG without transparency they will not be a lot to take.
1) Explain what is the problem in keeping with transparency.

2) doesn't help

3) Not the fact that less I like more. But that's the project.
PS. In the draft fill up the picture. Created several resolutions and formats. Then optimization. Get 10 times the picture is smaller than the original. Output formats: MozJpeg and Webp. But the question is not relevant. - erich.Bergstrom commented on March 23rd 20 at 18:55
@erich.Bergstrom, the problem is that transparency is not needed, and you use it, and it probably causes a problem when converting. - Jairo39 commented on March 23rd 20 at 18:58
@Jairo39, you can specify transparency when you create the file?
To fill the background, it is necessary to use an additional 3 steps:
create an extra layer
move to the background
paint over it

The output image is displayed, but I want less action.
Wanted to solve it using imagemagick or something thread a console to manipulation was less. - erich.Bergstrom commented on March 23rd 20 at 19:01
@erich.Bergstrom, it's not about import and export. By the way, if you've installed ghostscript, imagemagick understands pdf at the entrance. - Jairo39 commented on March 23rd 20 at 19:04
What kind of export?
Save as.. > png?

Yes, I know that it is possible from pdf to png and jpg, but not with me. Upload only jpg or png. The quality was good, chose png. - erich.Bergstrom commented on March 23rd 20 at 19:07
@erich.Bergstrom, yeah, like save as. And there off the alpha channel. Or the same in save for web. In my opinion, you complicate their lives. - Jairo39 commented on March 23rd 20 at 19:10
@Jairo39, save using "Save for Web" there you can specify a white pad. And now all is normally displayed.

But now the edited image of 250Kb turned 700Kb when the quality fell a bit.

In General, I thought over the phrase "In my opinion, you complicate their lives." and decided not to swim against the current. Modified the website, now png are displayed without processing. Movements less, the quality is better, size is smaller. All gut!

PS. It is a pity that the mystery of png and is not disclosed. But now it is secondary. Question closed. - erich.Bergstrom commented on March 23rd 20 at 19:13
@erich.Bergstromif you want to improve something, get solution to following problems:
- convert PDF to PNG locally via IM/GS and not through Photoshop and save to PNG 8bit greyscale
- optimize the resulting PNG (and this is the image of the document?) with a decrease in the number of colors to, for example, 32 (not necessarily via IM - for example, through pngnq or a similar tool - whichever will perform better).

It is productive steps that will save time and effort. The solution to this problem with PNG, which is stored in an obviously incorrect format - an unproductive direction. - Jairo39 commented on March 23rd 20 at 19:16
I do not understand the phrase about "wrong format". If you show the picture on the website in png, it is displayed properly on all devices, even with the background, though without. The problem was only in the conversion only to imagemagick. So about "wrong format" does not agree without good facts.

Photoshop normally optimizes out of the box. Walked FileOptimizer on the highest setting. Out of the 250 received 225Кб, so not critical. When you save in photoshop, indexed color was even less than 32.

About PDF I do not understand the word at all.
Let me explain: For example a website under Wordpress, which loads a pdf file. And then what? How to tell him that you need him to png and display it on the website? For example I do not understand Your logic in this proposal for optimization. Note also that pages can be more than one.
And immediately looking ahead to say that you can show yourself pdf. But again, this is not my option for a variety of reasons. Starting from SEO and finishing the look. - erich.Bergstrom commented on March 23rd 20 at 19:19
@erich.Bergstrom, I don't understand what you persist is incorrect because it contains extra information - the alpha channel, as many as eight extra bits, it is obvious from the output of the identify. It makes no sense to deal with it because for your application it is not needed.

I give you advice based on what you convert a PDF locally in Photoshop is a waste of time, given that it is completely automatizarea. And you for some shit now, talk about the PDF download on the website, that does not fit you described prior to this process. Honestly, I don't have much desire to sort out this mess the problem description. - Jairo39 commented on March 23rd 20 at 19:22
The file is saved with the background, look at the size:

imagemagick - on my server, photoshop installed locally.
Okay, okay understood. - erich.Bergstrom commented on March 23rd 20 at 19:25
March 23rd 20 at 18:54
PNG with transparency, most likely. The alpha channel in different programs is interpreted in different ways. Maybe black, maybe white, maybe as checkered. The conversion goes like this: PNG->preflight (something like a BMP in memory) with the information layers -> compression to JPG. Here the alpha is filled with the colour of the background substrate, in this case black. Black text on a black background!

To check in word make part of the text, for example, red. Posmotrite what happens
You are right, black square and red letters.

convert pict.png -alpha background pict.jpg
get the white background - erich.Bergstrom commented on March 23rd 20 at 18:57

Find more questions by tags image processingbashLinux