Anyway.
For quite a while, I would resize and rescale wallpapers to the nearest standard monitor aspect ratio before adding them to my collection or uploading them in one of my wallpaper updates. To facilitate doing this, I wrote a script in PHP that I could give the dimensions and the target aspect ratio to, and it would calculate the closest dimensions that I could resize the image to in order to achieve that aspect ratio, to minimize the amount of editing I'd have to do.
Like I said in the first sentence of this post, I don't know if I ever made the existence of this script known here, so this post will do just that. But first, an overview of its features.
- When supplying the image dimensions, you can either type them in manually, or upload the image.
- When selecting the aspect ratio, there are a number of common aspect ratios available in a dropdown for easy access.
- You can also specify a custom aspect ratio, for if you're a n00b and don't know your monitor's aspect ratio, or you're editing something for a mobile device that might use some weird aspect ratio.
- It returns a minimum of two resolutions and a maximum of four, and tells you the difference in number of pixels for each dimension, so you can decide which one you want to use.
- The resolutions returned require an absolute minimum amount of editing.
- Added: Ability to specify a custom aspect ratio.
- Added: Reducing the supplied custom aspect ratio, as the function that looks for target resolutions needs this to be reduced.
- Added: Slightly better error messages. Now, instead of just insulting you, they also tell you what you did wrong, so you can go fix it, you horrible person.
- Changed: Dimension differences were previously "width bigger, height smaller", etc., they are now pixel differences per dimension (i.e. "width + 8 pixels, height - 4 pixels").
- Changed: Better input verification (regular expressions go).
- Removed: Arbitrary restriction on image width and height that existed because of my previous shitty input verification.
Reducing a fraction programmatically is a fairly simple process, but involves calculating the greatest common denominator of the two values, which is a rather interesting calculation. However, once you have the GCD, you simply divide the two values by said GCD and there you go, reduced fraction. This is how I reduce the values provided in the custom aspect ratio boxes so that the script will work correctly.
Anyway, here's what you've probably been wanting this entire time if you're still reading this: the link. Enjoy. It's rather lacking in bells and whistles, but oh boy is it ever functional.
No comments:
Post a Comment
I moderate comments because when Blogger originally implemented a spam filter it wouldn't work without comment moderation enabled. So if your comment doesn't show up right away, that would be why.