Categories
photos

Bumble bee

This is probably one of the first photos I took with the K20D when I got it last year.

Categories
General

Speeding up GD when making 2 sizes

Summary: If you’re using GD to generate 2 image sizes from an original, first generate the larger resized image, then generate the smaller size based on the resized image (not the original) to save a tiny bit of execution time.

I’m working on a webcam project where I need to pull in a large webcam image and resize it to 2 smaller sizes. The first user to visit the webcam page in a while triggers a resize, so speeding up the resize operation means they won’t have to wait long for the page to appear.

First, to get the execution time for a block of PHP code:

$startexec = microtime(true);

/* code you want to measure goes here */

$endexec = microtime(true) - $startexec;

This is for PHP 5+ – see the microtime entry in the manual if you’re working with an earlier PHP version.

There are a lot of ways to fetch a remote image, such as fopen() and CURL, but imagecreatefromjpeg($url) has been working fine for me so far. Here’s the code to get the external image, resample it, delete the old resized image if it exists, then write out the new version.

$bigimage = imagecreatefromjpeg($bigpath);

$midimage = imagecreatetruecolor($midwidth,$midheight);

imagecopyresampled($midimage,$bigimage,0,0,0,0,
$midwidth,$midheight,$bigwidth,$bigheight);

if (is_file($midpath))
unlink($midpath);

imagejpeg($midimage, $midpath);

On my testing machine it was taking about 1.2 seconds to do this twice, using a 2048×1536 original to generate both smaller-sized images. I found that by doing the mid-sized resample first, then using the mid-sized image for the smaller resample, resulted in a slightly faster execution time of a little less than 1 second.

That’s not much of an improvement, so next I’m going to investigate using ImageMagick instead of GD since that could be twice as fast.

Update: After a bit of testing I’m not seeing much difference between using GD (around 0.88 seconds) and ImageMagick (around 0.75 seconds), at least for the sort of resizing I’m doing – from 2048×1536 down to 850×638 and 500×375.

Categories
General

flickpress 1.9.1

This release adds one big feature, refines a few things introduced in the last release, and fixes some bugs.

First the bugs: A discussion about WP_DEBUG on the wp-hackers list inspired me to turn it on track down the avalanche of warnings, notices, and errors that flickpress was causing. Actually, it wasn’t that bad and fixing the issues didn’t take long. The major change was in the widget code – I was still using pre-2.8 widget functions. So, if you’re using the widget you may will need to check re-enter your settings. I also found and fixed a few breadcrumb problems in the popup tool.

Refinements: Thanks to some feedback from Gustav, I changed the before/between/after caption text fields to allow HTML. This can be used for a variety of things, such as breaking the caption into two lines or wrapping the caption with a tag to use custom style. The last version added simple ThickBox lightbox support, but in case you wish to use another lightbox method I added a custom lightbox option that works with plugins like LightBox Plus.

New feature: On the settings page you can now specify default licenses for photo searches. This will save you a few clicks if you always search for photos licensed the same way.

Get flickpress 1.9.1 at the WordPress Plugin Directory or by upgrading as usual in your WordPress admin panel.

Categories
photos

Growing tomato

We’ve got a few tomato plants growing in containers. The little cherry-sized ones like this one are doing pretty well.

Categories
General

oEmbed FlickrLinkr 0.4

This update adds a bunch of options to customize the appearance of embedded Flickr images and their captions. Here’s what you can do now:

  • Specify classes for the container div and image to control their layout/appearance.
  • Change the order of the title and author in the caption, or omit the author from the caption.
  • Specify text (including HTML) to insert before, between, and after the caption elements.

Get oEmbed FlickrLinkr 0.4 at the WordPress Plugins Directory.

Here’s an example with aligncenter on the div and some HTML in the text at the start of the caption (might change if I change the settings later – that’s how oEmbeds work):

http://www.flickr.com/photos/izik/4802765013/