thumbGen

This plugin creates a function called thumbGen() that allows to show any image in the specified size. It saves all generated thumbs in a cache directory under uploads.

Download last version from WordPress repository
(or search for it on your “add plugins” page)

Documentation

Installation

Just donwload the zip file, upload it to your wordpress vía install plugins page (or uncompress it to your wordpress wp-content/plugins/ folder) and activate it. Once activated the plugin is ready to be used by calling its main function (see “Usage” section below).

Requirements

This plugin has been tested under the 2.8.0+ version of  WordPress. Anyway, since this doesn’t use any wordpress function (just PHP) I thing it could work under any version of WordPress. For the grayscale function it uses th GD Library.

The generated images are saved under the wp-content/uploads/cache/ folder. If the folder doesn’t exist, the plugin will automatically create it. If the image don’t save under that folder, you should check if it is writable.

Probably this plugin will work in almost every servers. If your server doesn’t support this plugin, please check the folder configuration. Otherwise please let me know.

Usage

To use this function you just need to use this line with a few parameters:

<?php thumbGen(image,width,height,crop,center,grayscale); ?>

image: the full URL of the original image you need to create a thumbnail from.
width: the width you need for the generated thumbnail.
height: the height you need for the generated thumbnail.
crop: if you want the thumbnail to be cropped (no image deformation) if the width and height are different from the original image, set this value as 1 or true. If you want the content of the thumbnail to be resized to fit the space (image deformation) set this to 0 or false.
center: the same usage as crop parameter. If the content of the thumbnail to be cropped from the center of the original image set this value to 1 or true. If you want the content of the thumbnail to be cropped from the top left of the original image set this to 0 or false.
grayscale: the same usage as crop and center parameter. If you want the generated thumbnail to be in grayscale, set this value to 1 or true. If you set this value as 0 or false, the thumbnail will be generated in the same colors of the original image.

Examples

In this example I’ll not explain detailed how this WordPress code works, but I’ll show this as an example of this plugin usage:

<?php
$img="";
$args = array(
'post_parent'    => $post->ID,
'post_type'      => 'attachment',
'numberposts'    => 1,
'post_mime_type' => 'image'
);
$attachs = get_posts($args);
if ($attachs) {
$img=wp_get_attachment_image_src($attachs[0]->ID,'full');
}
if(!empty($img)){
?>
<img src='<?php thumbGen($img[0],171,56,1,1,0); ?>' alt='' />
<?php
}
?>

This example reads the first attached image of a post and save it’s information in a variable called $img. In the thumbGen function the first parameter is $img[0] and that’s the image URL. The second and third parameters are the width and height of the generated thumbnail we need. The rest of the parameters are the crop, center and grayscale options.

Known issues

This plugin works with all jpg, gif and png images, BUT if any of those original images has transparency, this plugin will replace it with a plain white color.

To Do

For the next version of the plugin, I’ll try to do the following features:

  • A plugin settings page to define the location of the cache folder and a button to empty the caché.
  • Add the possibility to omit some of the parameters (just send the url, width and height and the other parameters to be default)
  • Allow the plugin to generate transparent images.
  • Add this plugin to the WordPress repository (soon!)

I hope you enjoy this plugin… and please let me know any bug you find!!! … thanks ;)

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Bitacoras.com
  • Meneame
  • Netvibes
  • StumbleUpon
  • Twitter

24 Comments Comments Feed

  1. Kenneth (23/02/2010, 18:00). Reply

    Does it support external images, outside my domain?

  2. admin (23/02/2010, 22:47). Reply

    No, I’m sorry, because it uses a PHP function to open the image, and because of that, it needs the original image to be in yout domain (otherwise it couldn’t open it). But you could save the image on your domain, I guess?

  3. Cristian (24/02/2010, 12:17). Reply

    I Love this plugin :)

  4. Victor (26/02/2010, 16:52). Reply

    how is it diferent than the new post thumbnail feature?

    http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/

  5. admin (01/03/2010, 00:35). Reply

    In response to Victor: a lot!….if you want to make a Gallery, you can’t use the post thumbnail feature. You can use this function in any image of your site…you can use it for banners, icons, etc.. and you don’t have to declare it on the file functions.php….it’s already declared. You can generate the image in b/w to make rollovers, but you can’t do it with the post thumbnail feature. I hope you enjoy it.

  6. Li-An (03/03/2010, 12:01). Reply

    It would be perfect if it could use custom fields too (to put a default image or changing a thumbnail).

    • admin (03/03/2010, 12:09). Reply

      Hi Li-An…could you explain more about your ideas?…it could be interesting….thanks ;)

      • Samuel (05/03/2010, 14:19). Reply

        I think that Li-An idea is about adding a custom field in the post containing the thumbnail URL when the thumbnail is created.

        This way, you can easily edit the thumbnail URL and change it for any other.

        And if the plugin checks for the custom field before start the thumbnail generation, you can add your own default thumb or whatever… :)

        I would like to see that feature too (in fact, maybe I’ll add this for my own use).

        • admin (05/03/2010, 15:39). Reply

          Mmmm…I think that your idea is the same that victor asked before, about the “new post thumbnail feature”… you could do it with that feature, but the idea of this plugin is to go beyond… to be able to generate any picture on your template, not just the post ones :)

  7. ThumbGen – Plugin, чтобы производить миниатюры | Pomoshh' WordPress (11/03/2010, 02:05). Reply

    [...] Себастьян Барриа, который освободил новый plugin: ThumbGen. То, что предлагает этот предмет кода, состоит в том, [...]

  8. ThumbGen – Plugin to generate miniatures | Help WordPress (11/03/2010, 02:06). Reply

    [...] have just be warned by Sebastián Barría who has liberated a new plugin: ThumbGen. What offers this code piece is to autogenerate miniatures from any image loaded in your [...]

  9. Li-An (13/03/2010, 18:37). Reply

    Sorry I did not answer before… Yes, Samuel was right with my question. I use already a plugin to generate different sizes of thumbnails for my blog. As the plugin seems to be abandoned, I’m searching for other solutions in the future. The plugin I use has the ability to check a custom field to see if there is an image defined before creation a thumbnail from the image attached to the post. It gives the opportunity to change easily a thumbnail (sometimes the cropping/resizing gives a bad thumbnail and it’s good to “force” with another image).

  10. ThumbGen: un plugin para generar thumbnails | TodoWordPress (14/03/2010, 15:04). Reply

    [...] Más información en la página oficial de thumbGen. Etiquetas: Imágenes, Plugins, thumbGen, WordPress [...]

  11. Cristian (16/03/2010, 13:43). Reply

    Estimado, te quiero felicitar por el excelente trabajo, este plugin ha sido el único que ha cumplido todas mis expectativas y el manejo de el es impresionante. Un abrazo gracias por compartir tu trabajo.

    • Sebastian Barria (21/04/2010, 14:37). Reply

      Muchas gracias Cristian. Espero poder ir mejorándolo con el tiempo. Gracias por tus felicitaciones :)

  12. gambuto (21/04/2010, 13:22). Reply

    But does it work that

    you can set a img size for the img in a post and for your homepage? So that you wil have a thumbnail on your homepage and an extended img inside the post

    • Sebastian Barria (21/04/2010, 14:36). Reply

      Of course!… that’s the idea of this plugin. You can have as many different image size you want from the same picture. One on the home page and one inside the post.
      Good luck!

  13. ronnie (25/04/2010, 10:02). Reply

    hi sebastián,

    thanks for the very useful plugin!
    one serious bug which you can easily fix:
    i tried to implement the plugin but received THE SAME PIC for every post! the reason is that i use the same picture name everywhere but in a different folder for each post.

    the plugin writes and reads the picture from the cache directory and disregards the case for images WITH THE SAME NAME.

    my solution was to insert into the $ruta var the additional folder info i needed. changed from:
    $ruta=”wp-content/uploads/cache/”;
    to:
    $ruta=”wp-content/uploads/cache/”.get_the_excerpt().”/”;

    thanks again!
    ronnie :)

  14. Dave (13/05/2010, 09:02). Reply

    Hi,

    Firstly, this plugin is great!

    However, I am trying to use it with custom queries, as I want to apply the function to images added via a custom field but when the URL gets parsed through thumbGen, i just get a white image whereas before, when i was using it on attachments, they were fine. Both the URLs for the images are the same and live in the same directory on the same domain.

    Any help would be hugely appreciated!

    Cheers

  15. Dave (13/05/2010, 12:44). Reply

    Actually, ignore my last comment. I have worked it out by doing a regex on the src attribute of the img element and then using that to get the original filename and running that through thumbGen. :)

    Even happier now

  16. ThumbGen: un plugin para generar thumbnails (22/06/2010, 19:50). Reply

    [...] Más información en la página oficial de thumbGen. Imágenes, Plugins, thumbGen, WordPress [...]

  17. Alonso (25/06/2010, 22:27). Reply

    Estimado,
    Primero que todo quiero agradecer con gran efusividad este plugin debido a que me ha ayudado mucho en los sitios que he creado apoyado por wordpress y ha funcionado a la perfección,
    Lamentablemente me ocurrió un problema en un único sitio, puedo instalar el plugin sin problemas, coloco el llamado a la función del plugin en mi template, pero no me aparece la redimensión de la foto, no aparece nada, estuve revisandolo con el inspector de firefox y me sale el siguiente error,
    Warning imagesx(): supplied argument is not a valid Image resource in…
    revisé la carpeta de uploads y cache y en esta última me crea una imagen en blanco del tamaño que le pido pero no me crea la imagen correspondiente,
    Que puede ser?
    De ante mano muchas gracias

    • Alonso (26/06/2010, 20:16). Reply

      Estimado, es sólo con el wordpress 3.0 que tengo problemas, las versiones en las versiones anteriores de wordpress funciona bien.
      Saludos y espero tu ayuda,
      Que estes bien.

  18. Daniel (29/07/2010, 08:27). Reply

    Tried it. Followed your instructions. Got an error (warning.. the plugin file, lines 36/37) WP 3.01.

    Oh well.. back to hacking TimThumb!

Add a Comment

Switch to our mobile site