0

Hello,

After uploading picture into a certain folder and record the filename in the database, I would like to print the database and the picture out.

Here is the code:

<?php    

$i=0;
while($data = mysql_fetch_array($result)){
$result2=($i%2)?'#DFA09D':'white';

    echo "<tr  bgcolor='$result2'> ";
    echo "<td>".$data['id']."</td>";
    echo "<td>".$data['judul']."</td>";
    echo "<td><img src='../photos/".$data['image']."'></td>";  
    echo "<td><a href='input_image.php?mode=edit&id=".$data['id']."'>Edit |<a href='input_image.php?mode=delete&id=".$data['id']."'>Delete</a></td>";
    echo "</tr>";    
$i++;   
}

?>  

One problem, the picture that I uploaded to the directory is way too large to be printed; I would like to turn it into thumbnail. Some pictures, are just right but they still need to be turn into thumbnail in the printed out database table.

How to do so?

3
Contributors
8
Replies
40
Views
4 Years
Discussion Span
Last Post by davy_yg
0

Perhaps I can use this script right away:

$dest = "photos/"
$desired_width = "50"
$src = ?

make_thumb($src, $dest, $desired_width);

function make_thumb($src, $dest, $desired_width) {

    /* read the source image */
    $source_image = imagecreatefromjpeg($src);
    $width = imagesx($source_image);
    $height = imagesy($source_image);

    /* find the "desired height" of this thumbnail, relative to the desired width  */
    $desired_height = floor($height * ($desired_width / $width));

    /* create a new, "virtual" image */
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);

    /* copy source image at a resized size */
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);

    /* create the physical thumbnail image to its destination */
    imagejpeg($virtual_image, $dest);
}

What is $src ? source image destination or source image filename?

Edited by davy_yg

0

Hello, I run the following script. Then, checked my photos2 folder for the thumbnail and I did not find it.

<?php

    // Creating Thumbnails

    $result = mysql_query("SELECT * FROM gallery") or die(mysql_error());
    $data = mysql_fetch_array($result);
    $filesource = "../photos/".$data['image'];

    $dest = "/photos2";
    $desired_width = "10";
    $src = $filesource;

    make_thumb($src, $dest, $desired_width);

    function make_thumb($src, $dest, $desired_width) {
    /* read the source image */
    $source_image = imagecreatefromjpeg($src);
    $width = imagesx($source_image);
    $height = imagesy($source_image);
    /* find the "desired height" of this thumbnail, relative to the desired width */
    $desired_height = floor($height * ($desired_width / $width));
    /* create a new, "virtual" image */
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);
    /* copy source image at a resized size */
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
    /* create the physical thumbnail image to its destination */
    imagejpeg($virtual_image, $dest);

    echo "success creating thumbnail";
    }


?>
0

This $data['image'] gives me filename. How to seperate the filename from the file extension?

    $result = mysql_query("SELECT * FROM gallery WHERE id=(SELECT MAX(ID)  FROM gallery)") or die(mysql_error());
    $data = mysql_fetch_array($result);
    $filesource = "../photos/".$data['image'];

    $dest = "../photos_thumb/".$data['image']."_thumb.jpg";
0

I basically try to change the filename; if I add _thumb.jpg, it turns out image1.jpg_thumb.jpg

Edited by davy_yg

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.