Jump to content

Interesting Thumbnail problem.


Accurax

Recommended Posts

Ok guys... this is a bit annoying (for me at least), so any input is really appreciated.

 

Quite simply im trying to save two copies of an uploaded file to my server, one at full size, and one at a specified thumbnail size.

 

Im having problems getting the thumbnail created on the fly.

 

Heres where im up to so far :

 

<?php
//create and save the thumbnail version of this picture.
// Load image
$image = open_image('*****need to get a path to my pic dir & the variable carrying the file name in here*****);

if ($image === false) { 
die ('Unable to open image'); 
}


// Get original width and height
$width = imagesx($image);
$height = imagesy($image);

// New width and height
$new_width = 100;
$new_height = 100;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Display resized image
header('Content-type: image/jpeg');
imagejpeg($image_resized);
die();
?>

 

 

Now, when i ad a static path to the open_image() function it works and i get a display of te reduced image.

 

However, whenever i try to add any kind of file path that contains a variable..... in order to allow me to create thumbnails for different users

 

****note: Im renaming all uploaded files to the users "username" as this is unique*****

 

heres my function file for open_image():

 

<?php

function open_image ($file) {
        # JPEG:
        $im = @imagecreatefromjpeg($file);
        if ($im !== false) { return $im; }

        # GIF:
        $im = @imagecreatefromgif($file);
        if ($im !== false) { return $im; }

        # PNG:
        $im = @imagecreatefrompng($file);
        if ($im !== false) { return $im; }

        # GD File:
        $im = @imagecreatefromgd($file);
        if ($im !== false) { return $im; }

        # GD2 File:
        $im = @imagecreatefromgd2($file);
        if ($im !== false) { return $im; }

        # WBMP:
        $im = @imagecreatefromwbmp($file);
        if ($im !== false) { return $im; }

        # XBM:
        $im = @imagecreatefromxbm($file);
        if ($im !== false) { return $im; }

        # XPM:
        $im = @imagecreatefromxpm($file);
        if ($im !== false) { return $im; }

        # Try and load from string:
        $im = @imagecreatefromstring(file_get_contents($file));
        if ($im !== false) { return $im; }

        return false;
}

?>

 

Id really appreciate any help with this .............. it seems to be that the script wont allow me to enter a variable as part of the path to the file i want resizing, and i dont know why.

 

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.