Custom Thumbnail problem

#1
[eluser]Ray G[/eluser]
I have a file called imageresize.php which generates thumbnail images
Code:
header('Content-type: image/jpeg');
function resampleimage($maxsize, $sourcefile, $imgcomp=0){
// SET THE IMAGE COMPRESSION
$g_imgcomp=100-$imgcomp;
  // CHECK TO SEE IF THE IMAGE EXISTS FIRST
  if(file_exists($sourcefile)){
  // FIRST WE GET THE CURRENT IMAGE SIZE
  $g_is=getimagesize($sourcefile);
    /********* CALCULATE THE WIDTH AND THE HEIGHT ***************/
    // CHECK TO SEE IF THE WIDTH AND HEIGHT ARE ALREADY SMALLER THAN THE MAX SIZE
    if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize){
    // LEAVE WIDTH AND HEIGHT ALONE IF IMAGE IS SMALLER THAN MAXSIZE
    $new_width=$g_is[0];
    $new_height=$g_is[1];
    } else {
    // GET VALUE TO CALCULATE WIDTH AND HEIGHT
    $w_adjust = ($maxsize / $g_is[0]);
    $h_adjust = ($maxsize / $g_is[1]);
      // CHECK TO WHICH DIMENSION REQUIRES THE SMALLER ADJUSTMENT
      if($w_adjust <= $h_adjust){
      // CALCULATE WIDTH AND HEIGHT IF THE WIDTH VALUE IS SMALLER
      $new_width=($g_is[0]*$w_adjust);
      $new_height=($g_is[1]*$w_adjust);
      } else {
      // CALCULATE WIDTH AND HEIGHT IF THE HEIGHT VALUE IS SMALLER
      $new_width=($g_is[0]*$h_adjust);
      $new_height=($g_is[1]*$h_adjust);
      }
    }
  //SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER THE LAST "." )
    $image_type = strrchr($sourcefile, ".");

    //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION
    switch($image_type) {
        case '.jpg':
            $img_src = imagecreatefromjpeg($sourcefile);
            break;
        case '.jpeg':
            $img_src = imagecreatefromjpeg($sourcefile);
            break;
        case '.png':
            $img_src = imagecreatefrompng($sourcefile);
            break;
        case '.gif':
            $img_src = imagecreatefromgif($sourcefile);
            break;
        default:
            echo("Error Invalid Image Type");
            die;
            break;
    }
  // CREATE THE TRUE COLOR IMAGE WITH NE WIDTH AND HEIGHT
  $img_dst=imagecreatetruecolor($new_width,$new_height);
  // RESAMPLE THE IMAGE TO NEW WIDTH AND HEIGHT
  imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $g_is[0], $g_is[1]);
  // OUTPUT THE IMAGE AS A JPEG.
  // THIS CAN BE CHANGED IF YOU WANT TRANSPARENCY OR PREFER ANOTHER FORMAT. MAKE SURE YOU CHANGE HEADER ABOVE.
  imagejpeg($img_dst);
  // DESTROY THE NEW IMAGE
  imagedestroy($img_dst);
  return true;
  } else {
  return false;
  }
}
// NOW CALL THE IMAGE FROM ANY OTHER PAGE WITH <img src="imageresize.php?maxsize=xxx&source=path/to/image/file" /> xxx=a value for the max size
resampleimage($_GET['maxsize'], $_GET['source']);
?&gt;

I have a function which queries mysql and returns image info then creates the html to show the thumbnail (shortened)
Code:
$images[] = '
          <a >filepath.'" rel="lightbox['.$row->cat.']" border="1">
            <img >filepath.'" border="0" alt="'.$row->fname.'" >
          </a>'."<br />";

Above code is not displaying correctly but it will produce something like this
Code:
<a href="/images/gallery/Test_Image.jpg" rel="lightbox[Forms]" border="1">
            <img src="imageresize.php?maxsize=150&source;=./images/gallery/Test_Image.jpg" border="0" alt="Test Image" >
          </a>

Now if I go to my page all I get is the alt tag instead of the thumbnail image. If I go to my browser and just put in
http://mysite.com/imageresize.php?maxsiz..._image.jpg
It works fine.
I tried the url/querystring fix but not working either

thanks in advance for the help

Ray

#2
[eluser]pickupman[/eluser]
You need a leading slash.
Code:
<img src="/imageresize.php?rest_of_url_here" alt=""/>

It may work from your homepage, but any other uri with a CI like structure, your link will be a relative path to that folder. The browser resolves CI urls like folders.
So
http://yoursite.com = http://yoursite.com/imageresize.php
http://yoursite.com/controller = http://yoursite.com/controller/imageresize.php
http://yoursite.com/controller/method = http://yoursite/controller/method/imageresize.php

The leading slash in front of the path means always from the root folder of your site. Get firebug or the like for your browser, and you will see these links loading in the net[work] tab.

#3
[eluser]Ray G[/eluser]
I tried that yesterday and it didn't work. But today it does. I can't explain it but not going to ask questions. Smile I think I was too busy messing with both the source and the imageresize locations and just missed the right combination.

Thank for the help.

Also if anyone needs a thumbnail generator they are more than welcome to copy this code. I am sure others may have done something like this, but always willing to help if I can. If a moderator want to put this somewhere for others to use they are more than welcome to do so, or if you want me to do it I will be happy to do so.

Ray


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.