3

(Note: The wording of the question has changed to take into account information I did not know about when I asked it.)

I have an image that looks enormous in a posted answer. I have tried to follow the accepted answer from https://meta.stackexchange.com/a/25052, namely to add m or s just before the extension. The s works nicely, but the result is too small. The m produces a solidly black rectangle, although the size is quite good.

What could be causing this, and how can I fix it?

The post in question is https://tex.stackexchange.com/a/685152. The image is from the output of a LaTeX run to pdf, subjected to processing with pdfcrop and convert as follows:

pdfcrop -margin 6 qcc.pdf
convert -density 300 qcc-crop.pdf qcc.png

The size of the png file is under 26kb so it doesn't, as far as I am aware, bump up against any size limits.

Question Preserve image transparency when resizing images deals with preserving image transparency; it has apparently been decided that if an image is transparent, the m sizing will result in a black background. I wasn't aware that my image was transparent, and that isn't a feature that's covered in regular documentation.

Since transparency (information provided in comments) is central to the problem, I have rephrased the question itself. I just want to know how to fix the problem, or avoid it in the first place.

12
  • It's occurring because the image resizer feature doesn't have proper support for transparency, which your image is making use of: Preserve image transparency when resizing images. As mentioned there, the m size parameter will convert transparency into black - resulting in the completely black image you see - and the s parameter will convert transparency into white - which is why it "works", but if you look closely, you'll see that the background color is different. May 9, 2023 at 1:43
  • To fix this, you'll need to find out how to make it generate an image with a white background instead of transparent. May 9, 2023 at 1:47
  • @SonictheAnonymousHedgehog -- It does say that an m image will be black, but I really don't understand why. And it doesn't tell me clearly what I can do to change it to something that can be read. May 9, 2023 at 1:48
  • 1
    As to why Imgur decided to blacken transparency on m images - we don't know why Imgur implemented it that way; that's their design decision. As far as what to do to change it to something that can be read, I said in my second comment above that you need to make it use a white background instead of transparent. As far as this being a duplicate, the bug part of this question has already been reported and has an official response in that link - to make this not a duplicate, I'd edit this to only ask the support question of how to fix it and link to that post for reference. May 9, 2023 at 1:53
  • @SonictheAnonymousHedgehog -- Thanks for your second comment. Transparency isn't something that is dealt with in normal (La)TeX processing. I will inquire of the individuals most likely to understand what's happening, but I suspect it's hopeless in the short term. May 9, 2023 at 1:53
  • You could make the image small but have the original size image open when clicked. I explain in this answer how that works: meta.stackexchange.com/a/388914
    – rene
    May 9, 2023 at 6:02
  • The 'trick' is just to convert it to jpg, which will automatically add a white background instead of transparent. I actually have to do this so frequently I have an Automator service set up on key command to do it. idk what platform you're on. I could help if it's Mac, but not Win or any nix. Here's your image as jpg if it's any use to you for now. i.stack.imgur.com/wTkVV.jpg [I don't have presence on the tex stack so I can't edit it in]
    – Tetsujin
    May 9, 2023 at 7:17
  • You've edited in the answer to what seems to be your main question (what's causing the black image?), so I assume your real question is "How can I make my transparent image medium-sized (using the 'm'-suffix) without it turning black?". Can you please clarify that?
    – Joachim
    May 9, 2023 at 10:23
  • You could create the image in a smaller size with something like convert -density 300 -resample 150 qcc-crop.pdf qcc.png May 9, 2023 at 15:40
  • If you would prefer a white background: convert -density 300 -background white -alpha remove -alpha off qcc-crop.pdf qcc.png May 9, 2023 at 15:41
  • Or you could skip the intermediate step with pdfcrop and do convert -density 300 -resample 150 -trim -border 6x6 -bordercolor white qcc.pdf qcc.png to get a cropped image with white background May 9, 2023 at 15:56
  • (or answer beamer questions -- with the white background resizing works fine :) ) May 9, 2023 at 16:17

1 Answer 1

5

You can use HTML instead:

<img src="https://i.stack.imgur.com/LLkgR.png" width="200">

<img src="https://i.stack.imgur.com/LLkgR.png" width="300">

Feel free to adjust the variable in the width parameter to your liking.

8
  • -1, this is way to practical. We'd rather fight with features of imgur ... ;)
    – rene
    May 9, 2023 at 13:58
  • 3
    Teams doesn't use imgur, so I have to resize like this over there anyway, so I just get used to it :P
    – Catija
    May 9, 2023 at 13:59
  • This appears doable, but can it be done directly within the stackexchange session? Creating the original image and posting it to imgur already requires transferring files between three computers, using sftp for the first transfer, and the stackexchange "browse" for the second, since specifying a url doesn't work. I'm quite knowledgeable about TeX, but entirely deficient as a sysadmin. May 9, 2023 at 14:02
  • 1
    I use the image uploader and then remove the manually created image placeholder and cut the bibliography reference so I have the image URL to use to manually type the HTML. It'd definitely doable. :) Let me know if that's not clear.
    – Catija
    May 9, 2023 at 14:23
  • @barbarabeeton not sure on what OS you are but in Windows I can copy an image on the clipboard and then paste it directly in the post editor and that works as well for files I copy from the File Explorer I assume something similar should be doable for *nix systems or macs.
    – rene
    May 9, 2023 at 14:25
  • @rene -- I'm on a Ubuntu Linux system (laptop), but I do all my TeX work on another, remote, *nix machine (a "private" system, which blocks automated access to personal account areas). I'm quite proficient at moving files around, but I haven't yet managed to master non-text area-defined screen copying. But thanks for the suggestion. May 9, 2023 at 14:37
  • @Catija -- I'll experiment, and come back for more explanation if I fail. Thanks. May 9, 2023 at 14:40
  • @Catija -- I finally figured it out. Many thanks! A width of "400" looks good to me for this example. May 9, 2023 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .