Jump to content

[SOLVED] auto thumbnail creation


chronister

Recommended Posts

Hello everyone,

 

I am trying to get a auto-thumbnail creation script working. I have been playing with this for over 6-7 hours between yesterday and today and cannot get it figured out. The problem with the code below is that it does not create the image on the server at all. Any help would be appreciated.

 

<?php

// this is for testing only, this var will come from a $_FILES field
$image_name='test_image.jpg'; 
// path that will contain the source image and destination image
$uploaddir='/full/path/to/image/directory/'; 
//set destination name, with path
$dst_image=$uploaddir.'thumb_'.$image_name;
//set the source image
$src_image=$uploaddir.$image_name;
// get the file extension
$ext = substr($image_name,strrpos($image_name,'.'));
// // determine which type of image it is
if($ext == '.gif')
{
$img = imagecreatefromgif($src_image);
}
elseif($ext == '.jpg' )
{
$img = imagecreatefromjpeg($src_image);
}
// set some vars for image creation x & y axis points
$dst_x=0;
$dst_y=0;
$src_x=0;
$src_y=0;
// set the destination width and height
$dst_w=imagesx($img)/2;
$dst_h=imagesy($img)/2;
//get the source width and height
$src_w=imagesx($img);
$src_h=imagesy($img);

function fastimagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) {

  if (empty($src_image) || empty($dst_image)) { return false; }
  if ($quality <= 1) {
    $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1);
    imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
    imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
    imagedestroy ($temp);
  } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {
    $tmp_w = $dst_w * $quality;
    $tmp_h = $dst_h * $quality;
    $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1);
    imagecopyresized ($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
    imagecopyresampled ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
    imagedestroy ($temp);
  } else {
    imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
  }
  return true;
}


fastimagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)


?>
<!-- this is the image that "should" be created -->
<img src="http://home.happyjoes.net/images/team/thumb_joe_whitty.jpg" />

 

This is my first foray into messing with image creation so I am sure that I am missing something very important or something very stupid. The person who can tell me what it is will have my life long respect and admiration.  ;D

 

Nate

Link to comment
Share on other sites

I tried incorporating that into it with no luck, so I searched a little more and found one in the php manual replies that did exactly what I want it to do. I will look over it and see what it's doing to learn, but for now it works and that is all I needed.

 

thanks,

 

Nate

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.