Template talk:Easy CSS image crop

Thinking through the maths for a percentage based version of this.


 * The width of the base image (bSize) is desired_image_width * 100 / (100 - crop_left_perc - crop right perc)
 * The height of the base image is then the above * original_image_height / original_image_width
 * cHeight is then the above * (100 - crop_top_perc - crop_bottom_perc) / 100
 * oTop is the height of the base image (calculated above) * crop_top_perc / 100
 * oLeft is the width of the base image (calculated above) * crop_left_perc / 100

That's mathy, but doable, and would make this really easy to scale - just change desired_image_width. I'd say we'll need helper templates for a couple of these. Adam Cuerden (talk)Has about 8.8% of all FPs. 06:56, 31 January 2024 (UTC)

As this moves towards release:
Subsidiary templates are:
 * Module:ImageRatio: This grabs information that would otherwise require manual inserting of data, vastly simplifying the template.
 * Template:Easy CSS image crop/bSize

Adam Cuerden (talk)Has about 8.8% of all FPs. 10:34, 31 January 2024 (UTC)
 * This template has an option to specify the width, but not the height. As an alternative to, could the template include a   parameter? Jarble (talk) 16:25, 3 March 2024 (UTC)
 * Theoretically, but it might be easier to have a second template for that, because it's not clear what expected behaviour would be if both height and width are specified, especially if the crop percentages don't line up. Adam Cuerden (talk)Has about 8.8% of all FPs. 16:31, 3 March 2024 (UTC)
 * There's no need for a second template. If a  parameter were included, the   would be calculated from   and  . Jarble (talk) 16:55, 3 March 2024 (UTC)
 * But what if both are set? And the crop percentages? It adds a lot of possibilities for failure. Also, the calculations using desired_height are completely different, since step one is figuring out what the size of the uncropped image is, which means that desired_width factors into every calculation the template does. Adam Cuerden (talk)Has about 8.8% of all FPs. 16:57, 3 March 2024 (UTC)
 * Only one of those parameters should be set, and setting both of them would be an error. We should assume that either  or   is included, but not both. If both of the parameters are included, the template should ignore the   and calculate the width from the.

Jarble (talk) 17:07, 3 March 2024 (UTC)


 * Well, this basically works out to if one, do this, if the other, do something completely different - none of the maths is the same between the two, hence why it may be easier to have a seperate template, as that also prevents the ambiguous situation. Because another valid interpretation might be to set the desired height and width, then use crop perc to set the offsets on one side (which is basically what CSS image crop does). Basically, I want to avoid situations where this acts unexpectedly (outside of obvious ones, like setting crop_left_perc and crop_right_perc to over 100 combined). Adam Cuerden (talk)Has about 8.8% of all FPs. 17:18, 3 March 2024 (UTC)
 * In that case, how would the  parameter be calculated? It could be a percentage of the   or , but not both. Jarble (talk) 17:45, 3 March 2024 (UTC)
 * Aye. The way it's calculated now is basically a reverse percentage. So desired_width / (100-crop_left_perc - crop_right_perc) * 100 - and then rounded to a whole number
 * To calculate it with height, it becomes substantially more complex, as we need to get the base height, then use the lua module ImageRatio to calculate the base width from that. Something like, offhand.
 * bSize= (desired_height / (100-crop_top_perc - crop_bottom_perc) *100 ) * ImageRatio
 * It's not really any more complex than desired_width after that, it's just all the other way around. If we're going to do that, we should probably convert everything to Lua, so that once we've calculated the base size (height and width), we can save the calculation to use in other calculations. We would need to be careful, though: The point of this is to be easy and too many options can make it hard again. Adam Cuerden (talk)Has about 8.8% of all FPs. 18:15, 3 March 2024 (UTC)