Jump to content

Thumbnail Image


xyn

Recommended Posts

Hey;

I've been trying to get my thumbnail script to work.

There are no errors produced, however the thumbnail

isnt being created, the dimentions are the same as the

original image.

 

I was hoping for advise on where the problem is, and how

to get around it; my code:

<?php
include_once($_SERVER['DOCUMENT_ROOT']."/config.inc.php");
$img_base   = $_SERVER['DOCUMENT_ROOT']."/images/uploads/";
$max_width  = base64_decode(Secure($_GET['w']));
$max_height = base64_decode(Secure($_GET['h']));
$image_file = base64_decode(Secure($_GET['s']));
$image_path = $img_base.$image_file;

$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if($ext == 'jpg' || $ext == 'jpeg')
{
    $img = @imagecreatefromjpeg($image_path);
}
elseif($ext == 'png')
{
    $img = @imagecreatefrompng($image_path);
}
elseif($ext == 'gif')
{
    $img = @imagecreatefrompng($image_path);
}
if($img)
{
    $width  = imagesx($img);
    $height = imagesy($img);
    $scale  = min($max_width/$width, $max_height/$height);

    if ($scale & 1)
{
        $new_width  = ceil($scale * $width);
        $new_height = ceil($scale * $height);
        $tmp_img = imagecreatetruecolor($new_width, $new_height);
        imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
        imagedestroy($img);
        $img = $tmp_img;
    }
}
/*
if(!$img)
{
#NO IMAGE _ CREATE _ ERROR _ IMAGE
}
*/

header("Content-type: image/jpeg");
imagejpeg($img);
?>

 

The image code:

image_thumb.php?s=NDg4MTNiOWU5MDY2YTFkOTQ0YjBiNTk4NDhiMTYxYjhmNGM5MGE1ZjJiNzViMzAwY2I5N2RlMTEzMmIzNTczYmQ0ZjE5MmIxLnBuZw==&w=MTAw&h=OTg=

Link to comment
Share on other sites

OK; I narrowed the error down a little:

if($img)
{
    $width  = imagesx($img);
    $height = imagesy($img);
    $scale  = min(ceil($max_width/$width), ceil($max_height/$height));

    if ($scale & 1)
    {
        $new_width  = ceil($scale * $width);
        $new_height = ceil($scale * $height);
	die($new_width."x".$new_height);
        $tmp_img = imagecreatetruecolor($new_width, $new_height);
        imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
	$img = $tmp_img;
    }
}

 

$scale returns "1"

which means its multiplying the current W/H by 1

ie why it doesnt change the size.

 

any ideas?

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.