PHP and Images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wtgee

    PHP and Images

    I posted this elsewhere but got no answer so I thought I would see if anyone
    here is smarter. :)

    I am creating a image management system and have a few questions, if anyone
    could help

    1) I read somewhere that storing images in a mysql database as a BLOB
    reduces speed and efficiency. Is this true? I don't expect to be serving
    many images although they could feasible get up to about 1000. I am instead
    opting to just store the filename in the database and use that to grab the
    image.

    2) Assuming the latter (using just the filename in the database), I have a
    question about file storad and dynamic images. Should I create the images
    at runtime, including thumbnails, or should I, when the image is first
    uploaded, create and save a thumbnail and a web version (maybe a 800 x 600
    image) and
    discard the high-quality uploaded image? My preview page could generate
    anywhere from one to 25 thumbnails so I am a little hesitant to dynamically
    create 25 thumbnails on a page; it seems to me that would have a definite
    performance problem. However, I am somewhat tempted to do this because I
    want the user to have the ability to easily change the thumbnail size and I
    don't to have run a script that, everytime they change the thumbnails size,
    loops through potentially 1000 images creating new thumbnails.

    Any help or ideas?

    Thanks,

    wtgee



  • Steve

    #2
    Re: PHP and Images

    On Sat, 26 Jul 2003 15:12:39 GMT, wtgee wrote:
    [color=blue]
    > I posted this elsewhere but got no answer so I thought I would see if anyone
    > here is smarter. :)[/color]
    [color=blue]
    > I am creating a image management system and have a few questions, if anyone
    > could help[/color]

    [snip]


    I'm no expert, so you will probably get better answers. Automatically
    creating thumbnails and storing them on disk is easy enough, and I tried
    that. However, if you're going to be deleting files too, don't forget to
    delete the relevant thumbnails in the same routine otherwise you'll clog up
    the server's disk.

    I have a 'gallery' section on my personal web site where the thumbnails are
    created on the fly when the page is loaded. It uses the GD1 library for
    this because my hosting service hasn't implemented GD2 (I used that when
    developing the site, on my local system, and it produced better thumbnails
    because I could use imagecopyresamp led() rather than imagecopyresize d() -
    but selah). If you want to check it out, to judge performance, the page is
    at:


    This page checks to see what subdirectories there are below it (using the
    name of each subdir for each thumbnail table) and creates thumbnails from
    all the jpg or png files in those sub-dirs. This means, to add a new image,
    all I do is drop the image file into the relevant directory - no HTML
    editing at all. To create a new section, I just create a sub-directory and
    moving images from one section to another is similarly easy. I also wanted
    to add captions to some images, so the page also looks for a .txt file with
    the same name as the image in the same dir. Creating captions this way is
    the work of a few moments using Notepad or Kwrite (depending which OS I'm
    using at the time).

    The thumbnails load fast enough for me (over a single 64k ISDN connection)
    - but your needs may be different.

    a+
    Steve

    Comment

    • David Walker

      #3
      Re: PHP and Images

      > 1) I read somewhere that storing images in a mysql database as a BLOB[color=blue]
      > reduces speed and efficiency. Is this true? I don't expect to be serving
      > many images although they could feasible get up to about 1000. I am[/color]
      instead[color=blue]
      > opting to just store the filename in the database and use that to grab the
      > image.[/color]

      Yep - good plan! There are two main problems with putting images in the
      database - one is speed, particularly on searching in the database, and also
      general access. The second is that usually databases are much more
      size-limited than the general webspace, so better to use the webspace than
      database... especially as theres no disadvantage to using the files anyway.
      [color=blue]
      > 2) Assuming the latter (using just the filename in the database), I have[/color]
      a[color=blue]
      > question about file storad and dynamic images. Should I create the images
      > at runtime, including thumbnails, or should I, when the image is first
      > uploaded, create and save a thumbnail and a web version (maybe a 800 x 600
      > image) and
      > discard the high-quality uploaded image? My preview page could generate[/color]

      What I decided to do is, on upload, create the thumbnail, and then just save
      the original file - I wanted to keep the original so then people have the
      choice to have a high quality image if they want it, and I just make this
      fit the layout by sizing it with css.
      [color=blue]
      > anywhere from one to 25 thumbnails so I am a little hesitant to[/color]
      dynamically[color=blue]
      > create 25 thumbnails on a page; it seems to me that would have a definite
      > performance problem. However, I am somewhat tempted to do this because I[/color]

      Dynamically generating all the thumbnails at runtime will be a huge waste of
      server resources!
      [color=blue]
      > want the user to have the ability to easily change the thumbnail size and[/color]
      I[color=blue]
      > don't to have run a script that, everytime they change the thumbnails[/color]
      size,[color=blue]
      > loops through potentially 1000 images creating new thumbnails.[/color]

      You could easily make a simply script to go through your image directories
      and generate new thumbnails. Even if it has to do 1000 and that takes a few
      minutes, its nothing compared to the time it'd take to keep generating new
      ones each time.

      David


      Comment

      Working...