Auto TinySrc WordPress Plugin

I’ve published a new WordPress plugin which I wrote for Ribot today, enabling anyone to use TinySrc on their site by simply adding it. Download it from WordPress.org.

TinySrc is a service provided by Sencha which dynamically shrinks your images according to the device accessing them. This helps shrink images for mobile, and will cut down the size of a site with a responsive design.

This plugin replaces all image tag src’s within your content with the tinysrc src (http://mysite.com/myimage.png becomes http://i.tinysrc.mobi/http://mysite.com/myimage.png), and provides a function to call in your themes to optimise those images.

To use the plugin, run through the following:

1. Upload `auto-tinysrc.php` to the `/wp-content/plugins/` directory

2. Activate the plugin through the ‘Plugins’ menu in WordPress

3. Place

<!–?php<br /–> if (function_exists(‘get_tinysrc_image’)) {
get_tinysrc_image(‘image_url’);
} else {
echo image_url;
} ?&gt;

in your templates to display any template images optimised, e.g.

<!–?php<br /–> $image_url = get_bloginfo(‘template_url’).‘/images/bonsai_404_error.png’;
if (function_exists(‘get_tinysrc_image’)) {
get_tinysrc_image($image_url);
} else {
echo $image_url;
} ?&gt;

4. To get a variable containing the url of an image with the tinysrc url use

<!–?php<br /–> if (function_exists(‘get_tinysrc_image’)) {    get_tinysrc_image(get_bloginfo(‘template_url’).‘/images/bonsai_404_error.png’, false);
} ?&gt;
  • brian

    Perfect, just what I was looking for. Thanks!

  • John Lopez

    Great work. Are there plans to update to the new http://src.sencha.io/ domain prefix?

    Cheers!

  • http://www.mark-kirby.co.uk kirby.mark

    Yes, and thanks for your comment. I’ll get this done this week sometime.

  • Andrew Nimm

    Hi Mark,

    I want to use your plugin with a slider script to return several urls for the same attachment:
    the size appropriate for the screen,
    the thumbnail of the same attachment,
    the full size for fullscreen viewing.

    The point of using tinysrc of course is to get a scaled down one for smaller screens, but my little function has to be able to return valid urls for the thumbnail and fullscreen versions too, for desktop, which my clumsy first version doesn’t.