Jump to content

thumbnail.php?database=thisdb&table=table&imgid=1&width=300 A little help Plz?


cwazybwo

Recommended Posts

Thumb.php?width=300&image=displaydbimage.php?id=1 doesn't work because the data is being fed wrong. the Thumb.php works very well with filesystem images, but not database images. How can I use a database image to make a thumbnail on the fly? I will be dealing with maybe millions of images and don't wanna use a filesystem. as you can see... http://geeksperhour.com/startthetour/databasetours/displayimage.php?id=1 the database works quite well, but i NEED to resize these BEFORE they are sent to the client. what php code will be able to convert the blog image to work with the thumbnail code!?

Link to comment
Share on other sites

if theyrll all goin to be the same width or height, you could put it in a global file somewhere and call it befor the display

 

well, i will call they using all sorts of different height and widths. I want the script to make it a thumbnail, i don't care if it takes a bit longer to load cause the server is working more. but I really want this all in one script, and make a thumbnail function in it. but my prob is sending the data in the right format to the thumbnail code

Link to comment
Share on other sites

I have googled all night tring to find this "data converter" code, gotta go to bed now, but can get emails(they go to my cell phone) Hopefully you guys can send me some links or code to help me out buy the time I wake up, thanks in advance!

Link to comment
Share on other sites

This is my display an image from db script:

 

<?php

 

// getdata.php3 - by Florian Dittmer <dittmer@gmx.net>

// Example php script to demonstrate the direct passing of binary data

// to the user. More infos at http://www.phpbuilder.com

// Syntax: getdata.php3?id=<id>

 

if($id) {

 

    // you may have to modify login information for your database server:

    MYSQL_CONNECT("localhost","geeksper_main","password");

    mysql_select_db("geeksper_main");

 

    $query = "select bin_data,filetype from binary_data where id=$id";

    $result = @MYSQL_QUERY($query);

 

    $data = @MYSQL_RESULT($result,0,"bin_data");

    $type = @MYSQL_RESULT($result,0,"filetype");

 

    Header( "Content-type: $type");

    echo $data;

 

};

?>

and the thumbnail script is....

 

<?php

 

# Constants

if(isset($height)){define(MAX_HEIGHT, $height);}else{define(MAX_HEIGHT, 10000);}

if(isset($width)){define(MAX_WIDTH, $width);}else{define(MAX_WIDTH, 10000);}

 

 

define(IMAGE_BASE, '');

//define(MAX_WIDTH, $width);

//define(MAX_HEIGHT, 300);

 

# Get image location

$image_path = "" . $image;

 

# Load image

$img = null;

$ext = strtolower(end(explode('.', $image_path)));

if ($ext == 'jpg' || $ext == 'jpeg') {

    $img = @imagecreatefromjpeg($image_path);

} else if ($ext == 'png') {

    $img = @imagecreatefrompng($image_path);

# Only if your version of GD includes GIF support

} else if ($ext == 'gif') {

    $img = @imagecreatefrompng($image_path);

}

 

# 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

        imagecopyresized($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,0,0,0);

    $c = imagecolorallocate($img,70,70,70);

    imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2);

    imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2);

}

 

# Display the image

header("Content-type: image/jpeg");

imagejpeg($img);

?>

 

sorry for the big posts, I just want to be understood. I want to "combine" these 2 scripts, so i can make thumbnails of database images on the fly.

Link to comment
Share on other sites

 

your need to get the user post the pic then add pic info to database ok.

 

 

 

<?php

// this our dedicated function that creates our resized images
function createImage($width, $height, $srcimg, $img_thumb)
{
    $srcImg = ImageCreateTrueColor( $width, $height ) or die('Problem In Creating image');

    if( function_exists('imagecopyresampled' ))
    {
        imagecopyresampled( $srcImg, $srcimg, 0, 0, 0, 0, $width, $height, ImageSX($srcimg), ImageSY($srcimg) ) or die('Problem In resizing img #' . $key);
    }
    else
    {
        Imagecopyresized( $srcImg, $srcimg, 0, 0, 0, 0, $width, $height, ImageSX($srcimg), ImageSY($srcimg) ) or die('Problem In resizing img #' . $key);
    }

    ImageJPEG( $srcImg, $img_thumb, 90 ) or die('Problem In saving img');

    imagedestroy( $srcImg );
}

if(isset($_POST['Submit']))
{
    $size[1] = 100;
    $size[2] = 200;
    $size[3] = 300;

    $filedir = './pics/';

    $thumbdir[1] = './pics1/';
    $thumbdir[2] = './pics2/';
    $thumbdir[3] = './pics3/';

    $prefix = '00005';
    $maxfile = '2000000';
    $mode = '0666';

    $userfile_name = $_FILES['image']['name'];
    $userfile_tmp  = $_FILES['image']['tmp_name'];
    $userfile_size = $_FILES['image']['size'];
    $userfile_type = $_FILES['image']['type'];

    if (isset($_FILES['image']['name']))
    {
        $prod_img = $filedir.$userfile_name;

        $prod_img_thumb[1] = $thumbdir[1].$prefix.$userfile_name;
        $prod_img_thumb[2] = $thumbdir[2].$prefix.$userfile_name;
        $prod_img_thumb[3] = $thumbdir[3].$prefix.$userfile_name;

        move_uploaded_file($userfile_tmp, $prod_img);
        chmod ($prod_img, octdec($mode));
        $srcimg = ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');

        $sizes = getimagesize($prod_img);

        $aspect_ratio = $sizes[1]/$sizes[0];

        if (($sizes[1] <= $size[1]) || ($sizes[1] <= $size[2]) || ($sizes[1] <= $size[3]))
        {
            $new_width = $sizes[0];
            $new_height = $sizes[1];
        }
        else
        {
            $new_height[1] = $size[1];
            $new_height[2] = $size[2];
            $new_height[3] = $size[3];

            $new_width[1] = abs($new_height[1]/$aspect_ratio);
            $new_width[2] = abs($new_height[2]/$aspect_ratio);
            $new_width[3] = abs($new_height[3]/$aspect_ratio);
        }

        // loop through each img width and call a dedicated function to
        // create different sizes of the uploaded image
        foreach($new_width as $cur_img => $cur_img_width)
        {
            // this function uses the variables set above
            createImage($cur_img_width, $new_height[$cur_img], $srcimg, $prod_img_thumb[$cur_img]);
        }
    }


// show the created images
    foreach($prod_img_thumb as $cur_img => $img_thumb)
    {
        echo '<h3>Img #' . $cur_img . '</h3>
<a href="' . $prod_img . '">
    <img src="'.$prod_img_thumb[$cur_img].'" width="'.$new_width[$cur_img].'" height="'.$new_height[$cur_img].'">
</a><br />
Dimensions: ' . $new_width[$cur_img] . 'px X ' . $new_height[$cur_img] . 'px';
    }
}
else
{
    echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">
    <input type="file" name="image"><p>
<input type="Submit" name="Submit" value="Submit">
</form>';
}

?>

Link to comment
Share on other sites

Well, I now see that that was not a database. it was a file system, i already did that last week. I need the same thing but to work storing the images on a database, and not just links to the images! I think the name of this "thread" says it all, Re: thumbnail.php?database=thisdb&table=table&imgid=1&width=300 A little help please?

 

I DONT want to use the file system to store images! I want the image in the database! but not thumbnails in the database, not links in the database, the REAL BLOG image data, like http://geeksperhour.com/startthetour/databasetours/displayimage.php?id=1 THAT DATA! why is this so hard!? I know someone has done things this way before, is this too hard for u guys or what!?

 

Again, no filesystem to store the pics, it HAS to be on the mysql database!

Link to comment
Share on other sites

Is what I am asking for really all that hard!? why are you guys having trouble fully understanding this!? GET databaseimagedata -> resize(thumbnail) script -> output to browser!

 

I can resize them as filesystem files just fine, I can display images stored in the database just fine. WHY CANT I COMBINE THE TWO AND GRAB THE DB IMAGE DATA FIRST, THEN RESIZE THE DATA AND OUTPUT IT TO THE BROWSER!? It seems kinda simple to me. I gave the code I am using above, so that you understand what is going on.

 

It may say noobie on here, but I understand alot of php/mysql/html! So, please don't talk dumb to me, I can handle the geek talk!

 

I did find this, http://www.weberdev.com/get_example-3446.html and made this with the code, but it looks like shit, why? and how can i fix it? http://geeksperhour.com/startthetour/databasetours/dbthumblive.php?id=1

Link to comment
Share on other sites

well, whatever, I got it to work myself! you guys suck! for anyone wondering, i used this script finally.....

 

<?php

 

 

if($id) {

 

    $link = @mysql_connect("localhost","geeksper_main","mypass") or die("Could not connect: " . mysql_error());

    @mysql_select_db("geeksper_main", $link);

 

    $query = "select filetype, bin_data from binary_data where id = $id";

    $result = @mysql_query($query);

 

    $data = @mysql_result($result,0,"bin_data");

    $type = @mysql_result($result,0,"filetype");

   

    Header( "Content-type: $type");   

   

    $size = 150;  // new image width

    $src = imagecreatefromstring($data);

    $width = imagesx($src);

    $height = imagesy($src);

    $aspect_ratio = $height/$width;

 

    if ($width <= $size) {

      $new_w = $width;

      $new_h = $height;

    } else {

      $new_w = $size;

      $new_h = abs($new_w * $aspect_ratio);

    }

 

    $img = imagecreatetruecolor($new_w,$new_h);

    imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);

 

    // determine image type and send it to the client   

    if ($type == "image/jpeg") {   

      imagejpeg($img);

    } else if ($type == "image/x-png") {

      imagepng($img);

    } else if ($type == "image/gif") {

      imagegif($img);

    }

    imagedestroy($img);

    mysql_close($link);

};

?>

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.