Externally Generate Thumbnails

I really like my zenphoto gallery (http://www.andermic.com/photos/) and I just started a "blog" to write about my photography. I would like to post images within the blog posts, but instead of uploading with the blog software and having to maintain two sets of images, I was wondering if it would be simple enough for me to link to a page that can get thumbnails of certain sizes for the blog. I started to write a script that caches the images and gets whatever size I ask for, but once again I really would rather not have to maintain two sets.

Here's the code I started if it helps to describe what I am trying to do.
`

$album = $_GET["album"];

$image = $_GET["image"];

$new_width = $_GET["size"];

if (file_exists('cache/'. $album .'/'. $image .'_'. $new_width .'.jpg'))

{

$tmp_img = imagecreatefromjpeg('cache/'. $album .'/'. $image .'_'. $new_width .'.jpg');

}

else

{

$file = imagecreatefromjpeg($album .'/'. $image);

$width = imagesx( $file );

$height = imagesy( $file );

$new_height = floor($height * ($new_width/$width));

$tmp_img = imagecreatetruecolor( $new_width, $new_height );

imagecopyresized( $tmp_img, $file, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

if (!is_dir('cache/'. $album))

{

mkdir('cache/'. $album);

}

imagejpeg($tmp_img, 'cache/'. $album .'/'. $image .'_'. $new_width .'.jpg', 100);

}

header('Content-Type: image/jpeg');

imagejpeg($tmp_img, NULL, 100);

imagedestroy($file);

imagedestroy($tmp_img);

`

Comments

Sign In or Register to comment.