Link to home
Start Free TrialLog in
Avatar of Toube
Toube

asked on

Php create thumbnails on the fly

Hi,

I trying to use this thumbnail.php script to show thumbnails of full size images:
Thumbnails on the fly

But I can't get the thumbnails to work.
Here how I call it:

echo "<img src=\"createThumbnails.php?img=../profiili/userAlbums/$folder_/$filename_&amp;height=50&amp;width=100&amp;folder=$folder_&amp;id=$user\" style=\"border: none; padding: 1px;\" alt=\"$text_original\" title=\"$text_original\"/></a>";

Open in new window


And the createThumbnails.php looks like this:

<?
# ----------------------------------------------------------------------
# DFN Thumbnailer
# http://www.digifuzz.net
# digifuzz@gmail.com
# ----------------------------------------------------------------------

# Constants

$user = $_GET['id'];
$userpictureSql = "select * FROM userphotos WHERE user_='$user' order by id";
$resultsqlquery = mysql_query($userpictureSql)or die(mysql_error());
$folder = mysql_result($resultsqlquery, 0, folder);

$IMAGE_BASE = "/public_html/intra/profiili/userAlbums/$folder/";

$image_file = $_GET['img'];
$MAX_WIDTH  = $_GET['mw'];
$MAX_HEIGHT = $_GET['mh'];


global $img;

# No Image?  No go.
if( !$image_file || $image_file == "" )
{
      die( "NO FILE FOUND.");
}      

# if no max width is set, set one.
if( !$MAX_WIDTH || $MAX_WIDTH == "" )
{
  $MAX_WIDTH="100";
}      

# if not max height is set, set one.
if( !$MAX_HEIGHT || $MAX_HEIGHT == "" )
{
  $MAX_HEIGHT="50";
}      
  
# Get image location
$image_path = $IMAGE_BASE . $image_file;

# Load image
$img = null;
//$ext = strtolower(end(explode('.', $image_path))); old way
$ext = pathinfo($image_path, PATHINFO_EXTENSION); // new way
/* old way
if ($ext == 'jpg' || $ext == 'jpeg') 
{
    $img = @imagecreatefromjpeg($image_path);
} 
else if ($ext == 'png') 
{
  $img = @imagecreatefrompng($image_path);
} 
else if ($ext == 'gif') 
{
  # Only if your version of GD includes GIF support
  $img = @imagecreatefromgif($image_path);
}
*/
$img = @imagecreatefromstring(file_get_contents($image_path)); //new way

# If an image was successfully loaded, test the image for size
if ($img) 
{
  # Get image size and scale ratio
  $width = imagesx($img);
  $height = imagesy($img);
  $scale = min($MAX_WIDTH/$width, $MAX_HEIGHT/$height);

  # If the image is larger than the max shrink it
  if ($scale < 1) 
  {
    $new_width = floor($scale*$width);
    $new_height = floor($scale*$height);

    # Create a new temporary image
    $tmp_img = imagecreatetruecolor($new_width, $new_height);

    # Copy and resize old image into new image
    imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, 

    $new_width, $new_height, $width, $height);
    imagedestroy($img);
    $img = $tmp_img;        
  }    
} 

# Create error image if necessary
if (!$img) 
{
  $img = imagecreate($MAX_WIDTH, $MAX_HEIGHT);
  imagecolorallocate($img,255,255,255);
  $c = imagecolorallocate($img,255,0,0);
  imageline($img,0,0,$MAX_WIDTH,$MAX_HEIGHT,$c);
  imageline($img,$MAX_WIDTH,0,0,$MAX_HEIGHT,$c);
}

# Display the image
header("Content-type: image/jpeg");
imagejpeg($img,",500);
?>

Open in new window


Any idea where the problem is?

Thanks.
Toby
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

Please ref this link, https://www.experts-exchange.com/questions/26476419/PHP-Thumbnail-Generator.html

It is very easy and works fine.
Avatar of Toube
Toube

ASKER

Thanks, tried it.. but not getting it to work either.

here's how I tried it:

Call the function:

$img1=create_right_size_image("../profiili/userAlbums/$folder_/$filename_, $folder_, $user, $index");	

echo "<div style=\"float: left; border: 1px solid #dadada; padding: 3px; margin: 5px;\"><a href=\"index.php?id=$user&amp;album=1&amp;img=$index\">".PHP_EOL;
echo "<img src=\"../profiili/userAlbums/$folder_/$img1\" style=\"border: none; padding: 1px;\" alt=\"$text_original\"/></a>";

Open in new window


Then the imageResize.php modified version:

<?php // imageResize.php RESIZE IT TO FIT A PREDEFINED SIZE


// A FUNCTION TO DETERMINE IF GD IS AT LEVEL 2 OR MORE
function get_gd_info($display=FALSE)
{
    // IS GD INSTALLED AT ALL?
    if (!function_exists("gd_info"))
    {
        if ($display) echo "<br/>GD NOT INSTALLED\n";
        return FALSE;
    }

    // IF GD IS INSTALLED GET DETAILS
    $gd = gd_info();

    // IF DISPLAY IS REQUESTED, PRINT DETAILS
    if ($display)
    {
        echo "<br/>GD DETAILS:\n";
        foreach ($gd as $key => $value)
        {
            if ($value === TRUE)  $value = 'YES';
            if ($value === FALSE) $value = 'NO';
            echo "<br/>$key = $value \n";
        }
    }

    // RETURN THE VERSION NUMBER
    $gd_version = preg_replace('/[^0-9\.]/', '', $gd["GD Version"]);
    return $gd_version;
}

// A FUNCTION TO MAKE AN IMAGE INTO THE RIGHT WIDTH FOR PAGE DISPLAY
// WILL WORK IF GD2 NOT INSTALLED, BUT WILL MAKE BETTER IMAGES WITH GD2
// INPUT IS THE IMAGE FILE NAME, OUTPUT IS AN IMAGE RESOURCE, OR FALSE IF NO RESIZE NEEDED
function create_right_size_image($image, $width=100, $folder, $user, $index)
{
/*
$userpictureSql = "select * FROM userphotos WHERE user_='$user' order by id";
$resultsqlquery = mysql_query($userpictureSql)or die(mysql_error());
$folder = mysql_result($resultsqlquery, 0, folder);
*/
$IMAGE_BASE = "/public_html/intra/profiili/userAlbums/$folder/"; //Get the image location
    // IS GD HERE?
    $gdv = get_gd_info();
    if (!$gdv) return FALSE;

    // GET AN IMAGE THING
    $source = imagecreatefromjpeg("$image");

    // GET THE X AND Y DIMENSIONS
    $imageX = imagesx($source);
    $imageY = imagesy($source);

    // IF NO RESIZING IS NEEDED
    if ($imageX <= $width)
    {
        return FALSE;
    }

    // THE WIDTH IS TOO GREAT - MUST RESIZE
    $tnailX = $width;
    $tnailY = (int) (($tnailX * $imageY) / $imageX );

    // WHICH FUNCTIONS CAN RESIZE / RESAMPLE THE IMAGE?
    if ($gdv >= 2)
    {
        // IF GD IS AT LEVEL 2 OR ABOVE
        $target = imagecreatetruecolor($tnailX, $tnailY);
        imagecopyresampled ($target, $source, 0, 0, 0, 0, $tnailX, $tnailY, $imageX, $imageY);
    }
    else
    {
        // IF GD IS AT A LOWER REVISION LEVEL
        $target = imagecreate($tnailX, $tnailY);
        imagecopyresized   ($target, $source, 0, 0, 0, 0, $tnailX, $tnailY, $imageX, $imageY);
    }
    return $target;
}


// SAMPLE CALLING SEQUENCE
// RESIZE THE FILE TO FIT PAGE WIDTH, IF NECESSARY
if ($imageblob = create_right_size_image($my_image_file))
{
    // CREATE YOUR NEW FILE NAME HERE?
    $my_new_image_file = '.$IMAGE_BASE.'/'.$index.'.'_tn.jpg'; // Use image location to save new thumnail file to

    // STORES THE IMAGE IN A NEW FILE NAME
    imagejpeg($imageblob, $my_new_image_file);
}
?>

Open in new window


Help is needed.
I think by now everyone has GD2 installed.  Here is a more modern version of a similar script.  It performs an upload and thumbnail creation process, storing the thumbnail image so that it does not have to be recreated every time.  If you have some experience with PHP you may be able to tailor this to your exact application needs.  It will handle JPG and PNG inputs, and could be modified to handle simple GIF images, too.  Please read it over carefully (code and comments) and post back with any questions.  The "resize" process starts around line 240.

<?php // RAY_upload_and_thumbnail.php
error_reporting(E_ALL);


// MANUAL REFERENCE PAGES YOU MUST UNDERSTAND TO UPLOAD FILES
// http://php.net/manual/en/features.file-upload.php
// http://php.net/manual/en/features.file-upload.common-pitfalls.php
// http://php.net/manual/en/function.move-uploaded-file.php
// http://php.net/manual/en/reserved.variables.files.php

// MANUAL PAGES THAT ARE IMPORTANT IF YOU ARE DEALING WITH LARGE FILES
// http://php.net/manual/en/ini.core.php#ini.upload-max-filesize
// http://php.net/manual/en/ini.core.php#ini.post-max-size
// http://php.net/manual/en/info.configuration.php#ini.max-input-time


// PHP 5.1+  SEE http://php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY
$uploads = 'RAY_junk';
if (!is_dir($uploads))
{
    mkdir($uploads);
}


// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT - ABOUT 8 MB
$max_file_size = '8000000';

// ESTABLISH THE MAXIMUM NUMBER OF FILES WE CAN UPLOAD
$nf = 3;

// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
$file_exts = array
( 'jpg'
, 'png'
)
;

// LIST OF THE ERRORS THAT MAY BE REPORTED IN $_FILES[]["error"] (THERE IS NO #5)
$errors = array
( 0 => "Success!"
, 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini"
, 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"
, 3 => "The uploaded file was only partially uploaded"
, 4 => "No file was uploaded"
, 5 => "UNDEFINED ERROR"
, 6 => "Missing a temporary folder"
, 7 => "Cannot write file to disk"
)
;




// IF THERE IS NOTHING IN $_POST, PUT UP THE FORM FOR INPUT
if (empty($_POST))
{
    ?>
    <h2>Upload <?php echo $nf; ?> file(s)</h2>

    <!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        ENCTYPE IN THE HTML <FORM> STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
        ABSENCE OF ACTION= ATTRIBUTE IN FORM TAG CAUSES POST TO SAME URL
    -->

    <form name="UploadForm" enctype="multipart/form-data" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php // CREATE INPUT STATEMENTS FOR UP TO $n FILE NAMES
    for ($n = 0; $n < $nf; $n++)
    {
        echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>" . PHP_EOL;
    }
    ?>
    <br/>Thumbnail Dimensions:
    <br/>Width <input name="w" />
    <br/>Height <input name="h" />
    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <strong>overwrite</strong> existing files.
    <input type="submit" value="Upload" />
    </form>
    <?php
    die();
}
// END OF THE FORM SCRIPT



// WE HAVE GOT SOMETHING IN $_POST - RUN THE ACTION SCRIPT TO UPLOAD THE FILS
else
{
    // THERE IS POST DATA - PROCESS IT
    echo "<h2>Results: File Upload</h2>\n";

    // ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
    // echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>" . PHP_EOL;

    // ITERATE OVER THE CONTENTS OF $_FILES
    foreach ($_FILES as $my_uploaded_file)
    {
        // SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
        $error_code = $my_uploaded_file["error"];
        if ($error_code == 4) continue;

        // SYNTHESIZE THE NEW FILE NAME
        $f_type    = trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
        $f_name    = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));

        // USE THIS FOR WRITING ON THE SERVER
        $my_new_file
        = getcwd()
        . DIRECTORY_SEPARATOR
        . $uploads
        . DIRECTORY_SEPARATOR
        . $f_name
        . '.'
        . $f_type
        ;

        // USE THIS FOR WRITING THE THUMBNAIL ON THE SERVER
        $my_new_tnail
        = getcwd()
        . DIRECTORY_SEPARATOR
        . $uploads
        . DIRECTORY_SEPARATOR
        . 'tn_'
        . $f_name
        . '.png'
        ;

        // USE THIS FOR PREPARING A URL LINK OR CALLING PHP FUNCTIONS
        $my_file
        = $uploads
        . DIRECTORY_SEPARATOR
        . $f_name
        . '.'
        . $f_type
        ;

        // USE THIS FOR PREPARING A URL LINK OR CALLING PHP FUNCTIONS
        $my_tnail
        = $uploads
        . DIRECTORY_SEPARATOR
        . 'tn_'
        . $f_name
        . '.png'
        ;

        // OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
        if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");

        // IF THERE ARE ERRORS
        if ($error_code != 0)
        {
            $error_message = $errors[$error_code];
            die("Sorry, Upload Error Code: $error_code: $error_message");
        }

        // GET THE FILE SIZE
        $file_size = number_format($my_uploaded_file["size"]);

        // IF THE FILE IS NEW (DOES NOT EXIST)
        if (!file_exists($my_new_file))
        {
            // IF THE MOVE FUNCTION WORKED CORRECTLY
            if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
            {
                $upload_success = 1;
            }
            // IF THE MOVE FUNCTION FAILED
            else
            {
                $upload_success = -1;
            }
        }

        // IF THE FILE ALREADY EXISTS
        else
        {
            echo "<br/><b><i>$my_file</i></b> already exists" . PHP_EOL;;

            // SHOULD WE OVERWRITE THE FILE? IF NOT
            if (empty($_POST["overwrite"]))
            {
                $upload_success = 0;
            }
            // IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
            else
            {
                $now    = date('Y-m-d');
                $my_bak = $my_new_file . '.' . $now . '.bak';
                if (!copy($my_new_file, $my_bak))
                {
                    echo "<br/><strong>Attempted Backup Failed!</strong>" . PHP_EOL;
                }
                if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
                {
                    $upload_success = 2;
                }
                else
                {
                    $upload_success = -1;
                }
            }
        }

        // REPORT OUR SUCCESS OR FAILURE
        if ($upload_success == 2) { echo "<br/>It has been overwritten.\n"; }
        if ($upload_success == 1) { echo "<br/><strong>$my_file</strong> has been saved.\n"; }
        if ($upload_success == 0) { echo "<br/><strong>It was NOT overwritten.</strong>\n"; }
        if ($upload_success < 0)  { echo "<br/><strong>ERROR: $my_file NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</strong>\n"; }
        if ($upload_success > 0)
        {
            echo "$file_size bytes uploaded.\n";
            if (!chmod ($my_new_file, 0755))
            {
                echo "<br/>chmod(0755) FAILED: fileperms() = ";
                echo substr(sprintf('%o', fileperms($my_new_file)), -4);
            }
            echo "<br/><a target=\"_blank\" href=\"$my_file\">See the file $my_file</a>\n";
        }
        // IF NO UPLOAD, DO NOT OVERWRITE ANY EXISTING THUMBNAIL
        else
        {
            die();
        }




        // RESIZE AN IMAGE TO FIT INSIDE A DEFINED TRANSPARENT SPACE
        // MAN PAGE: http://php.net/manual/en/ref.image.php

        // ACQUIRE THE DIMENSIONS - MAY NEED SOME SANITY TESTS?
        $thumb_w   = $_POST["w"];
        $thumb_h   = $_POST["h"];

        // CREATE THE THUMBNAIL IMAGE RESOURCE AND FILL IN TRANSPARENT
        $thumb = imageCreateTrueColor($thumb_w, $thumb_h);
        imageSaveAlpha($thumb, TRUE);
        $empty = imageColorAllocateAlpha($thumb,0,0,0,127);
        imageFill($thumb, 0, 0, $empty);

        // GET ORIGINAL IMAGE DIMENSIONS
        $array = getImageSize($my_file);
        if ($array)
        {
            list($image_w, $image_h) = $array;
        }
        else
        {
            die("NO IMAGE $my_file");
        }

        // ACQUIRE THE ORIGINAL IMAGE
        $image_ext = trim(strtoupper(end(explode('.', $my_file))));
        switch(strtoupper($image_ext))
        {
            case 'JPG' :
            case 'JPEG' :
                $image = imagecreatefromjpeg($my_file);
                break;

            case 'PNG' :
                $image = imagecreatefrompng($my_file);
                break;

            default : die("UNKNOWN IMAGE TYPE: $my_file");
        }

        // GET THE LESSER OF THE RATIO OF THUMBNAIL H OR W DIMENSIONS
        $ratio_w = ($thumb_w / $image_w);
        $ratio_h = ($thumb_h / $image_h);
        $ratio   = ($ratio_w < $ratio_h) ? $ratio_w : $ratio_h;

        // COMPUTE THUMBNAIL IMAGE DIMENSIONS
        $thumb_w_resize = $image_w * $ratio;
        $thumb_h_resize = $image_h * $ratio;

        // COMPUTE THUMBNAIL IMAGE CENTERING OFFSETS
        $thumb_w_offset = ($thumb_w - $thumb_w_resize) / 2.0;
        $thumb_h_offset = ($thumb_h - $thumb_h_resize) / 2.0;

        // COPY THE IMAGE TO THE CENTER OF THE THUMBNAIL
        imageCopyResampled
        ( $thumb
        , $image
        , $thumb_w_offset
        , $thumb_h_offset
        , 0
        , 0
        , $thumb_w_resize
        , $thumb_h_resize
        , $image_w
        , $image_h
        )
        ;

        // (OPTIONAL) SHOW THE NEW THUMB IMAGE DIRECTLY IN BROWSER
        // header('Content-type: image/png');
        // imagePng($thumb);

        // WRITE THE THUMBNAIL TO DISK
        imagePng($thumb, $my_new_tnail);

        // RELEASE THE MEMORY USED BY THE IMAGE RESOURCES
        imageDestroy($thumb);
        imageDestroy($image);

        // CREATE AN IMAGE LINK FOR THE BROWSER
        echo '<br/><a target="_blank" href="' . $my_tnail . '">See the Thumb ' . $my_tnail . '</a>' . PHP_EOL;

    // END FOREACH ITERATOR - EACH ITERATION PROCESSES ONE FILE
    }
}

Open in new window

Best regards, ~Ray
Avatar of Toube

ASKER

Hi Ray,

nice script thanks. I will probably be using the first part of the script also but now I just need to resize or create thumbnails of already found images on my webserver directory.

What would be the right way to use the script? Is it possible to use last part of the resizeing thumbnails part and creating the thumbnails on the fly or do these thumbnails have to be created with the upload of the images?

Regards,
Toby
You can redact the script to create thumbnails on the fly.  Look for the variable named $my_file -- that would be a URL of the original image.  Look at lines 306-308.  That shows how to send the image directly to the browser.

I wish I could help with this, but I teach PHP and I am full-time in the classroom today, so this will be my last look until this evening.  If you get stuck, please post back and I will check in after class.

Best, ~Ray
Avatar of Toube

ASKER

Hi,

ok no problem. I have been using php for some years at a basic level so bare with me ok.
Here what I'm trying to do: I'm looping my images from mysql database and displaying them in a while loop like this:
$index = 0;
while($index < $photocount)
{	
	$imageid_ = mysql_result($resultsqlquery, $index, id);
	//$thumbnail_ =  mysql_result($resultsqlquery, $index, thumbnailname);
	$phototext_ =  mysql_result($resultsqlquery, $index, phototext);
	$text_ = html_entity_decode($phototext_);
	$text_original = html_entity_decode($phototext_);
    $text_ = substr($text_original,0,20);
    $count_ = strlen($phototext_);	
	$filename_ = mysql_result($resultsqlquery, $index, filename);
	$defaultphoto_ = mysql_result($resultsqlquery, $index, defaultphoto);
	$folder_ = mysql_result($resultsqlquery, $index, userfolder);
	if ($count_ > 20)
	{$dots = "...";}
	else{$dots = "";}

	createThumbs($filename_,$photocount);
	
$index ++;
} // end while	

Open in new window


and here the function in where I echo out the thumbnails.. but at the moment it will only echo one image insted of 3 images.. something is not right with my for loop inside the createThumbs function.

function createThumbs($filename_,$photocount){

for ($i=0; $i < $photocount; $i++){
        // RESIZE AN IMAGE TO FIT INSIDE A DEFINED TRANSPARENT SPACE
        // MAN PAGE: http://php.net/manual/en/ref.image.php

        // ACQUIRE THE DIMENSIONS - MAY NEED SOME SANITY TESTS?
        $thumb_w   = $_POST["w"];
        $thumb_h   = $_POST["h"];
		$my_file = $filename_;
        // CREATE THE THUMBNAIL IMAGE RESOURCE AND FILL IN TRANSPARENT
        $thumb = imageCreateTrueColor($thumb_w, $thumb_h);
        imageSaveAlpha($thumb, TRUE);
        $empty = imageColorAllocateAlpha($thumb,0,0,0,127);
        imageFill($thumb, 0, 0, $empty);

        // GET ORIGINAL IMAGE DIMENSIONS
        $array = getImageSize($my_file);
        if ($array)
        {
            list($image_w, $image_h) = $array;
        }
        else
        {
            die("NO IMAGE $my_file");
        }

        // ACQUIRE THE ORIGINAL IMAGE
        $image_ext = trim(strtoupper(end(explode('.', $my_file))));
        switch(strtoupper($image_ext))
        {
            case 'JPG' :
            case 'JPEG' :
                $image = imagecreatefromjpeg($my_file);
                break;

            case 'PNG' :
                $image = imagecreatefrompng($my_file);
                break;

            default : die("UNKNOWN IMAGE TYPE: $my_file");
        }

        // GET THE LESSER OF THE RATIO OF THUMBNAIL H OR W DIMENSIONS
        $ratio_w = ($thumb_w / $image_w);
        $ratio_h = ($thumb_h / $image_h);
        $ratio   = ($ratio_w < $ratio_h) ? $ratio_w : $ratio_h;

        // COMPUTE THUMBNAIL IMAGE DIMENSIONS
        $thumb_w_resize = $image_w * $ratio;
        $thumb_h_resize = $image_h * $ratio;

        // COMPUTE THUMBNAIL IMAGE CENTERING OFFSETS
        $thumb_w_offset = ($thumb_w - $thumb_w_resize) / 10.0;
        $thumb_h_offset = ($thumb_h - $thumb_h_resize) / 10.0;

        // COPY THE IMAGE TO THE CENTER OF THE THUMBNAIL
        imageCopyResampled
        ( $thumb
        , $image
        , $thumb_w_offset
        , $thumb_h_offset
        , 0
        , 0
        , $thumb_w_resize
        , $thumb_h_resize
        , $image_w
        , $image_h
        )
        ;

        // (OPTIONAL) SHOW THE NEW THUMB IMAGE DIRECTLY IN BROWSER
        header('Content-type: image/png');
        imagePng($thumb);

        // WRITE THE THUMBNAIL TO DISK
        imagePng($thumb, $my_new_tnail);

        // RELEASE THE MEMORY USED BY THE IMAGE RESOURCES
        imageDestroy($thumb);
        imageDestroy($image);

        // CREATE AN IMAGE LINK FOR THE BROWSER
        echo '<br/><a target="_blank" href="' . $my_tnail . '">See the Thumb ' . $my_tnail . '</a>' . PHP_EOL;

    // END FOREACH ITERATOR - EACH ITERATION PROCESSES ONE FILE
    }
}

Open in new window


Any ideas?

Thanks.
Toby
Hey, Toby.  I'm on lunch break right now.  If you want to process these in batches of more than one, you must write the files to disk and optionally produce an HTML <img tag.  If you just want to render one image to the browser, that's OK, and you can have multiple instances of the rendering script in the same web page.  Each instance of the script can render just one image.  Check the PHP man page for ImagePNG().

I'll check back later today, ~Ray
Avatar of Toube

ASKER

Hi Ray,
Yes that's what I'm looking for, producing multiple thumbnail images in a batch so that the page and images load quicker. Now the images are fully loaded and that can take time and that's why I want to load thumbnails of the images instead.

You can check the page out here, an example:
user: guest
pwd: guest321

This user has upload a few images that are fully loaded.
http://intra.tobiasfransman.net/kayttajat/index.php?id=14

Regards,
Toby
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Toube

ASKER

Thanks for the advices.

Regards,
Toby
Was there something wrong with this answer?  I provided you with tested and working code samples, yet you marked the grade down to a "B" -- please read the grading guidelines and explain what you were expecting that you did not get in the answer.
https://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26

I would be glad to write your application for you, for pay, but I just don't have enough time to do this amount of work for free.  EE is a good place to get questions answered, but not to find free programming help.
Avatar of Toube

ASKER

Hi,
Sorry the hear that. Many other ee-experts have have helpt me out and given me scripts that I needed. Sorry for taking your valuable time.

Regards,
Toby
But what did you expect?  How could I have run test scripts on your machine?  I demonstrated all of the principles with tested and working code examples (at least I thought I did), so what was missing from the answers?