pauamma: Cartooney crab wearing hot pink and acid green facemask holding drink with straw (Default)
Res facta quae tamen fingi potuit ([personal profile] pauamma) wrote in [site community profile] dw_dev2020-09-06 07:29 pm
Entry tags:

Question thread #91

It's time for another question thread!

The rules:

- You may ask any dev-related question you have in a comment. (It doesn't even need to be about Dreamwidth, although if it involves a language/library/framework/database Dreamwidth doesn't use, you will probably get answers pointing that out and suggesting a better place to ask.)
- You may also answer any question, using the guidelines given in To Answer, Or Not To Answer and in this comment thread.
potofsoup: (Default)

[personal profile] potofsoup 2020-09-07 01:37 am (UTC)(link)
I've noticed that DW seems to impose its own image sizing to images in posts (example: I wanted the width of the images on this post to be 80%, and they are clearly not. Clicking on them gives me the full size image, which I don't want, either.)

So:
(a) what are the default resizes? Is it to a specific pixel height or width?
(b) is there any way I can change it on my end so that my images show up as a % of container width instead of being forced to be too small?

[personal profile] pinterface 2020-09-07 04:09 am (UTC)(link)

Hrm... it looks like that's caused by the code trying to fit images into the screen height, not just its width. That's certainly a choice.

It doesn't appear to be documented anywhere, but looking at the code, I think you can add the imageshrink-exempt class to the <img> tags to get what you want (e.g., <img src="..." class="imageshrink-exempt" width="80%">). At least, that seems to work poking at it in the inspector.

potofsoup: (Default)

[personal profile] potofsoup 2020-09-07 05:04 am (UTC)(link)
ah, that's super helpful! Thank you! :D
roadrunnertwice: Me looking up at the camera, wearing big headphones and a striped shirt. (Default)

[personal profile] roadrunnertwice 2020-09-07 08:35 pm (UTC)(link)

Hello! I made the image shrinking CSS/JS.

If an image is inside either a <table> or a <div style="..."> element, we don't mess with its sizing, because we assume someone's trying to make it line up with something specific.

So that's the official way to say "size it exactly like this" -- put it inside a table or a div with inline styles. The imageshrink-exempt class is an implementation detail, and we'd rather you don't rely on it, since we don't want your stuff to change if we change that implementation.

We've done a few iterations on the shrink behavior already, and I've always got my eye out for more improvements we could make in the future. This case is an interesting one just because the "zoomed" size is so unusably huge; I'll need to ponder that.

There might be a way to treat the width/height attributes as the max size for the "zoomed" state; would that fit what you want to have happen? Where the "squished" state tries to respect the user's device, but the "zoomed" state tries to respect the size hints of the post's author (instead of the raw pixel dimensions of the image file)?

Edited (adding some speculation) 2020-09-07 20:37 (UTC)
potofsoup: (Default)

[personal profile] potofsoup 2020-09-08 04:11 am (UTC)(link)
Hi! Thanks for responding! It's super helpful to know that throwing it in a table or a div would solve this -- definitely easier than remembering the imageshrink-exempt class. Just to clarify -- the div needs to have an inline style defined, or can an unadorned div suffice?

It'd definitely be nice if the "zoomed" state respects my width definitions! Or if the shrink wasn't trying to fit to screen height. There's definitely webcomics out there that have a reasonable max width but no max height considerations because nowadays people just scroll. (Instagram is changing that behavior again, but not fully). For example, SMBC (see example from smbc feed here: https://smbc-comics-feed.dreamwidth.org/1103365.html ). At least it's better than tumblr, which basically resizes things to fit to 1024 height, and therefore makes tall webcomics too low-res to actually read...
roadrunnertwice: Rebecca on treadmill. (Text: "She's a ROCKET SCIENTIST from the SOUTH POLE with FIFTY EXES?") (Rocket scientist (Bitter Girl))

[personal profile] roadrunnertwice 2020-09-08 06:01 am (UTC)(link)

Just to clarify -- the div needs to have an inline style defined, or can an unadorned div suffice?

Yeah, it needs an inline style. Well, more precisely, it just needs a style attribute. An empty style="" attribute works fine.

That exemption isn't really meant for "normal content" images like a photo or a comics page; it's meant for stuff inside some kind of decorative markup like a character sheet or a nav thingy, where the sizes of things need to line up just so. For casual images, the HOPE has always been that you just post it and it's fine (plus or minus a little bit of click-to-zoom). But we're kind of still getting there.

What's tricky is the amount of (kinds of stuff) x (ways in which stuff gets posted) x (ways in which stuff gets displayed). Like,

  • Pixel dimensions match intended display size at 1x (SMBC; QC) vs. px decoupled from display size so it looks good at high-DPI (your comics).
  • Integral image meant to be viewed in toto (any non-pano photo, whether landscape or portrait) vs. "navigable canvas" image meant to be viewed in parts, through a movable viewport (comics with vertical panel flow and no splash pages).
  • Mobile vs. desktop.
  • Bare img tag vs. image in a link (typically pointed at the full size image).
  • Handcrafted post intended for DW vs. markup in a feed that came from who knows where.
  • Height/width attributes carefully chosen for the purpose at hand vs. height/width attributes auto-filled by an image host's "click for embed HTML" copypasta.
  • 1000 journal styles worth of reading pages.

So for a portrait of a person, you definitely want to keep the image inside the viewport by default, which means constraining the height. But that plays hell with a 4-comi style strip, so you need click-to-zoom. But click-to-zoom only fixes strips that aren't inside links (the QC feed); the SMBC feed still looks kinda hosed. But you don't want to break link-clicking, so you need some other way to control zooming, maybe a little hover control or something? But making that work on EVERY JOURNAL STYLE starts getting kind of prohibitive, and besides, the link goes to a full size version of that image anyway, so I haven't gotten that one solved yet. And then we've got your issue, where the pixel dimensions aren't related to the intended display size.

Well, I'm rambling. Anyway, I figured out how to limit the "zoomed" state to the provided height/width attributes, but haven't figured out how to skip displaying the "zoomable" cursor in that case for images that are already the size they'd "zoom" to. Maybe that's not a huge problem; I'll mull it over a bit more.

potofsoup: (Default)

[personal profile] potofsoup 2020-09-08 06:44 am (UTC)(link)
mmmm yeah it's a pretty tough nut to crack. I used to do img tags with pixel widths in the 500-700 range, depending on how much I want the vertical to show on the page, but recently switched to % widths to avoid it being atrocious to mobile users (more of an issue on AO3 than here). I also used to have web-sized images rather than the larger images, but given the range of screen resolutions nowadays, combined with my laziness and the increased speed of the internet, it's just easier to go with full resolution.

It makes sense that you'd want photos or portraiture to fit vertically on the screen, so I just may be the odd person out in wanting to post comics, etc. And I've gotten in the habit of clicking through to SMBC nowadays to read a long strip, so it's not terribly inconvenient, especially since now I know the div trick!

Then again, maybe if either height or width is specified as a percentage on the image, the person might be wanting it a specific way? It was definitely a bit weird to me when my img tag refused to behave in the way I'd intended, and I didn't know why or how I could get around it. (though that might be a documentation issue). But I totally see your point re: random images being brought in that have unhelpful width/height attributes, combined with the wide range of widths for the post container (probably ranging from 300-1000px). Awkwardness regardless, tbh. Tumblr does it awkwardly, too -- inline images below an arbitrary pixel threshold gets displayed as-is (I think 320px wide), and over that gets forced into 100% wide, so if I wanted a 400px img to stay 400 px, I'd have to add 100px of whitespace, or add a "do not resize this" class to the image.

Anyways, thank you so much for the info about the div/table tags, and for doing all this to make it work better! I shall use the tags judiciously!
roadrunnertwice: DTWOF's Lois in drag. Dialogue: "Dude, just rub a little Castrol 30 weight into it. Works for me." (Castrol (Lois))

[personal profile] roadrunnertwice 2020-09-08 10:16 pm (UTC)(link)

Hmm, now that you got me thinking about it again, I've thought of a few more improvements:

  • Just bail out of squishing for any image that includes inline CSS in its style="..." attribute! That's an extremely clear way for people to say "I'm handling it myself."
  • Add a new "semi-squished" state with a max width but no max height, and use it on images whose height is more than twice their width. Anything like that is almost definitely not a portrait; probably 70% chance it's a tall comic or meme.

That would still squish your comics more than you want, but if we used your width attribute to make click-to-zoom max out at "legible" instead of "stupid," maybe that wouldn't be that bad? Plus you could always just use inline CSS to do whatever specific thing you want.

roadrunnertwice: Silhouette of a person carrying a bike up a hill (Bike - Carrying)

[personal profile] roadrunnertwice 2021-02-01 06:36 pm (UTC)(link)

Hi! Pardon the necro-post, but since I told you about the more awkward workarounds for image squishing, I wanted to let you know that there are now easier ways to deal with this!

  • If you set pixel height/width attributes on the image tag, it still shrinks the image if needed but will respect those dimensions as the max size for the “zoomed in” state. (Percent h/w attributes are against html spec, so we don't really handle those.)
  • If you set a style="(some css)" attribute on an image tag, we don’t squish it at all. So you can use that to set an exact size calculated however you want.
  • “Tall” images (where height > 2x width) get squished to fit their width, but are allowed to scroll off the viewport; we don’t force them to fit on a single screen anymore.

Those are all things we discussed later in the thread, but now they’re live on the site. I hope they make things nicer!

potofsoup: (Default)

[personal profile] potofsoup 2021-02-04 02:45 am (UTC)(link)

Ah, thank you so much for resurrecting this post! I noticed the image changes on the smbc comics since the code push and rejoiced! And the other things make perfect sense re: image sizing. Thank you so much for making my dreams come true <333

potofsoup: (Default)

[personal profile] potofsoup 2020-09-07 05:12 am (UTC)(link)
the other responder says that it's probably because they trying to get it to fit to screen height, which seems to check out. I have other externally-hosted images that respect my width attribute (example) so I don't think it's a hosting issue... And since I can't hotlink DW images to AO3, I prefer to just upload once externally and link everywhere... Thanks for looking into this!
momijizukamori: Green icon with white text - 'I do believe in phosphorylation! I do!' with a string of DNA basepairs on the bottom (Default)

[personal profile] momijizukamori 2020-09-07 08:11 pm (UTC)(link)
This is a result of a fix designed to keep absurdly large images from blowing out people's reading pages - there is a way to basically say 'no really I want it to be this big' but I don't remember what it was offhand - I will flag the dev who wrote that code though, he will know the answer!
potofsoup: (Default)

[personal profile] potofsoup 2020-09-08 02:02 am (UTC)(link)
Thank you! The dev answered! :D