Showing posts with label gallery. Show all posts
Showing posts with label gallery. Show all posts

Monday, 23 December 2013

Gallery Thumbnail Support using Imagick

Real Thumbnail Assets

Recently we improved our gallery offering for enhanced listings and the UI we use to show these gallery images displays them as 120x80px thumbnails with click to enlarge displaying the original image.

For our first release of the gallery we just set the height and width using CSS on the original image. This approach is simple although the gallery page can be slow loading due to it downloading full sized copies of the assets rather than scaled down versions.

Using imagick we created 180x180px thumbnails which gave us some big file size savings leading to much faster loading times of the main gallery. Some of the images have gone from 250Kb+ right down to between 10Kb and 20Kb.

Creating Existing Image Thumbnails

For creating thumbnail versions of images that have already been uploaded we wrote a basic PHP script to transverse the gallery directory and use imagick to convert them into their respective thumbnails.

We decided to use _small as a suffix for thumbnail images so if we had an image named image.png its thumbnail would be image_small.png we also have a fixed image name.

The command to convert the image is simple and only has a few parameters,
/usr/bin/convert -thumbnail 180 /path/to/image/image.png /path/to/image/image_small.png

The script we used was PHP but you could accomplish this using a simple bash script,
$baseDir = '/path/to/the/gallery';
$dh = opendir($baseDir);
while (($filename = readdir($dh)) !== false) {
    if ($filename != '.' && $filename != '..') {
        $fileArray = explode(".", $filename);
        $newFileName = $fileArray[0] . '_small.' . $fileArray[1];
        exec('/usr/bin/convert -thumbnail 180 ' . $baseDir . '/' . $filename . ' ' . $baseDir . '/' . $newFileName);
    }
}

Create Uploaded Image Thumbnail

When a user uploads an image to their gallery we also create a thumbnail of the upload using the imagick PHP module.

Another approach would be to use exec or passthru to execute the system command above although we feel using the module give us more control and we also do not need to make a system call etc..
$nameArray = explode(".", $filename);
$newFileName = $nameArray[0] . '_small.' . $nameArray[1];
$thumb = new Imagick($filename);
$thumb->thumbnailImage($width, $height);
$thumb->writeImage($newFileName);

It is as simple as that we decided not to use GD for creating the thumbnails although this is a possible path you could go down. One good thing about using GD is it has better support as a module if your using a shared host but we can install all the modules we need using APT.

Conclusion

Adding support for true thumbnails to our gallery offering has allowed us to decrease page load time and save bandwidth as well which are both good things. It also saves downloading 1Mb files that may not be viewed.

Soon we will be adding support for unlimited image uploads to enhanced listings so providers can then upload as many images as required so keep a look out for this in the new year.


On a side note this is our 50th blog post and we will be writing a round up of 2013 by having a look at what has been release and the new features and products The Care Homes Directory offers.

Friday, 29 November 2013

New Feature Release: Galleries

Improved Image Gallery

We have been working hard recently improving our current enhanced listings image support by adding a new gallery page and tab to all enhanced listings allowing home owners to upload five 1Mb images from their browser.

Currently the feature list is as follows,

  • Support for main image which is displayed on all enhanced listings tabs.
  • Upload five images of your home
  • High resolution 1Mb images
  • Dedicated gallery page for displaying gallery images
  • Spotlight image support for displaying large versions (provided by lighter)
  • Aspect ratio preservation on all images

Gallery and Editor

We plan to add support for converting assets into high resolution, medium resolution and thumbnail by using the ImageMagick PHP module.


Gallery Page

You can sign up for one year enhanced listings which costs £50+vat by completing the short form and making payment using Google Wallet all major credit and debit cards are accepted.


Image Spotlight

On a closing note our integration of Double Click for Publishers is progressing well and we hope to be releasing it in the new year, we feel our website has some good placements to offer advertisers and by using DFP we can offer these direct to potential customers.