thumbGen

WordPress plugin

VERSION 2.5.5 RELEASED!!!

This plugin is made for developers. It creates a function named thumbGen() that allows to show any image in the specified size. Additionally you can specify values like crop, center, rotation and effects.

It saves all generated thumbs in a cache folder, so it won’t overload your server at all.

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

License

Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

Donations

Well… I put this at the begining not because I’m doing this plugin to make some money, but because this is a lot of incentive to make more plugins like this. As every developer, I will always be happy to recieve your donations for my work and it will make me happier to keep updating this plugin.

Is very easy to donate… try it!

Documentation

Installation

Just donwload the zip file, upload it to your wordpress via install plugins page (or uncompress it to your wordpress wp-content/plugins/ folder) and activate it. Once activated se the main folder and default iage (in settings/thumbGen) and 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.9.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 cache folder specified in the config page. If you have any problem you should check your settings.

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 code:

<?php thumbGen(image,width,height,additional_parameters); ?>

image: the full URL of the original image you need to create a thumbnail from (needed).
width:
the width you need for the generated thumbnail (default=0 – if not specified it gets the proportional value from the specified height).
height:
the height you need for the generated thumbnail (default=0 – if not specified it gets the proportional value from the specified width).
note: if you don’t specify the with AND height (or if you set both to 0), the image will be generated in the source size.

Additional parameters

filename: some people have troubles with duplicated names, so I’ve added this parameter for you to specify a new filename (or ID or something like that) in order to differentiate each file (if not set it will use the source filename).
md5: by default, the images are generated with an md5 encode filename. If you don’t want the generated file to have an encoded name set this to 0
force: force thumb creation, even if it already exists (default=0) (NOT RECOMENDED! – use it just for testing or debugging)
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 (default=1).
halign: horizontal align of the croped image. You can set it to left, center or right (default=center)
valign: vertical align of the croped image. You can set it to top, center or bottom (default=center)
effect: you can apply two effects: grayscale and sephia
rotate: you can specify a rotation angle
background: hex color (like #ffffff) to apply on the background ONLY when you rotate the image. If you don’t want a color applied you can set this to transparent (default=transparent)
return: if set to 1 (or true) the image name will be returned instead of printed (default=0).

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,"effect=grayscale&halign=left&valign=top"); ?>'
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 defined in the string in the format parameter=value, concatenated with an &. the values not specified will use their default value.

To do

  • Recieve a lot of donations!: I have faith in you!
  • And, of course, if you have any idea on how to improve this plugin, please let me know

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

92 Comments Comments Feed

  1. Alejandro (12/04/2012, 18:10). Reply

    Hola Sebastián

    Estoy implementando tu plugin (muy útil, por cierto) en un sitio que está en una carpeta de un sitio y me tira error ya que supone que el sitio está en el root.
    Lo arreglé modificando la linea 37:

    $sitePath=WP_CONTENT_DIR.”/..”;

    Saludos

  2. Ian (19/04/2012, 09:57). Reply

    I think this is great! Took me a while to get working as on local host in a sub dir, but its working now!

    Im using it to size the post thumbnail, so had to make sure I was getting the image source path correct in order to generate the cached thumb otherwise the image was black.

  3. Adrian (19/04/2012, 10:11). Reply

    Hola Sebastian necesito comunicarme contigo para hacer un plugin. Ya sabes mi correo

Add a Comment

Suscribirme a los siguientes comentarios vía email (también puedes suscribirte sin comentar.

Switch to our mobile site