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
https://forums.phpfreaks.com/topic/40171-interesting-thumbnail-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.