Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    Ok, im looking for a way to upload a picture of any size, store it into my database and table. The format is:

    database : table : Column Name

    products : messages : picture

    I have the html to upload a file, and the php to handle it, but heres where i need help.

    I need to :
    1. Resize picture to say, 150x150 px, then store it in the spot shown above.

    2. Retrieve the picture and show it when a user wants a page.

    the code for 1 and 2 would be on different pages so i need to know where one stops and the other begins.

    Thanks for any help,
    Jordan
    If its not in Family Guy its not worth it.

  2.  

  3. #2
    Member nepharo's Avatar
    Join Date
    Jun 2003
    Posts
    73
    Member #
    1729
    You don't store a picture on a database, you store the link to the picture. The picture can be of any size, you use regular html to show it any size you want in the page. So, to show a image pulled from the DB with specific dimensions you would do this:
    <img src="<?=$imageLink ?>" width="<?=$width ?>" height="<?=$height ?>">

    if you know sql, and you should if you're using databases, you retrive the location of the image like so:
    Code:
    <?
    // connect to sql, blah , blah , blah
    $sql = "SELECT image, width, height FROM table_name WHERE condition;
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    
    echo "<img src='$row[image]' width='$row[width]' height='$row[height]'>";
    ?>
    I cannot self terminate, you must lower me into the fire.

  4. #3
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Actually, you can store a picture in your database if you insist (as a BLOB (Binary Large OBject)), but it's highly recomended not do so (as nepharo points out).
    This will bloat your database and make it slow !(extremely slow if you don't index it, or use full string searches, or delete random previously stored images).

    However, I would not use HTML to downsize lifted images. If you downsize an image of 3MB to a display size of 150 px (which would constitute an equivalent imagesize of approx 30K) the browser would still need to download the full 3MB picture binary to display it (meaning an eon of time before display).

    There are some GD functions available in PHP to downsize images on the fly, and present them in a resampled massively downscaled size. I'll see if I can dig one up in the near future. (going to bed now, and with new years eve, guests, children and so forth tomorrow, it might be a day or two before your new and shining example code appears)

    Happy New Year by the way!
    S. Rosland

  5. #4
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    Thanks both of you guys. So i've ruled out storing in the database as a BLOB, so I'm gonna set up a folder to keep the pictures in.

    There are some GD functions available in PHP to downsize images on the fly
    Sounds exactly like what im looking for, so when ever you get a chance to find em would be awsome.

    On another note, is there any lamens terms info on the indexes and full string searching could you send one my way? I'm really new to mysql and i have no idea how to yuse indexes to my advantage. or what they are even.

    Thanks,

    Jordan
    If its not in Family Guy its not worth it.

  6. #5
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Originally posted by jf1288
    Sounds exactly like what im looking for, so when ever you get a chance to find em would be awsome.
    Jordan, you really need to take a look at PHP manual. It'll be of great help while you are learning PHP.

    PHP Manual: http://www.php.net/manual/en/index.php
    GD Functions: http://www.php.net/manual/en/ref.image.php

    And google for tutorials on the subject.
    There and Back Again :Ogre:

  7. #6
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    awsome thanks a bundle. I taught myself the little php i know so that manual is answering a lot of questions for me.

    Thanks again

    Jordan
    If its not in Family Guy its not worth it.

  8. #7
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Here's an image rescaling script. You can play around with it. It will send headers to the browser when the "imagejpeg()" function is called, so it can't be used with any other HTML.

    If you want to use to produce images within a defined HTML page, you can name this script something (name.php for example), and call it in your HTML code like so: <img src="name.php">.

    (remember you have to have PHP compiled with the GD library to get this to work)

    PHP Code:
    <?php
        $file
    ="path/to/file/img.jpg";
        
    $size=180//new image width
        
    $src=imagecreatefromjpeg($file);
        
    $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);

          
    imagejpeg($img);
          
    imagedestroy($img);

    ?>
    S. Rosland


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:56 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com