Improve image upload: fixes thumbnails that are too small
One issue with the way Osclass currently uploads images is that thumbnail images may appear too small, with excess white space around them. This issue is most noticeable when uploading smaller images.
Here is the original full-size image:
This is the thumbnail image that is generated. Notice how small the actual image appears.
After the fix as outlined below, you can expect a thumbnail like this:
What causes this issue?
This issue stems from the way Osclass processes the original uploaded image, which is used to create three subsequent images(sizes shown are default):
- a normal image (640x480)
- a preview image (480x340)
- a thumbnail image (240x200)
To create the normal image, the original uploaded image is reduced in size and overlaid onto a new "blank" white image that is 640x480. If the original image is smaller than this size, the image is simply overlaid as-if, centered. This can leave excess white space around the image. If watermarks are enabled, the watermark is applied at this point to the normal image.
The preview image is then created directly from the normal image. Finally, the thumbnail image is generated from the preview image.
Here's a visualization of the process:
To fix this, each of the 3 image sizes should be created individually from the original image, rather than being created from re-sized versions of the normal image. This is a very easy change to make:
- Edit file ItemActions.php located in /oc-includes/osclass/.
- On lines 1286 and 1291, change:
That's it! Note: the specific line numbers may change, but they'll be "around" those lines.
- Since this 'fix' is applied to a core Osclass file, it will be overwritten during an upgrade.
- Watermarks will not show up on either preview or thumbnail images (should not be a big deal for most people)
Notes and references
--Jesse 14:18, 21 December 2011 (CET)