Categories
General

Unexpected output during plugin activation

WordPress 3 has a neat new check during plugin activation that generates a scary notice if the plugin generates any “unexpected output.” Sadly, the current version of flickpress was generating the scary notice. WordPress doesn’t provide any of the unexpected output and Apache’s error log wasn’t very enlightening either. I started deactivating, commenting out code blocks, then reactivating. It turned out the issue was in the table installation function. I was using this deprecated code:

require_once(ABSPATH . 'wp-admin/upgrade-functions.php');

…which should be this instead:

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

So, if you’re having trouble tracking down the source of this notice in your own plugin, carefully check everything it’s doing during activation.

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
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/

Categories
General

flickpress 1.9

This update adds some caption options, ThickBox support, moves the widget into the main plugin, and updates the phpFlickr library to 3.0. The new caption options let you switch the order of title and author, and put arbitrary text before, between, and after the caption parts. I moved the widget into the main plugin, so you may need to make sure it’s still in your sidebar. If you enable ThickBox support in the options then clicking an inserted Flickr image will display the largest image size available (up to Large) in a ThickBox window.

The plugin should work with the latest version of WordPress, currently 3.0.

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