Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2006
    Location
    Houston, TX
    Posts
    6

    Unanswered: Manipulating Image/Video Size

    I am writing a script to allow users to upload images and videos. In order not to take up alot of space or bandwidth I have decided to resize the images/videos to a smaller size. Once they are resized I will then save them to a database on my server.

    Here's the big question...

    When a query is called for these images/videos I want to resize them to their original size. Will this cause my pages to load slower and will this use more memory and processor resources with every page view due to the resize computation?

    Thanks in advance...

  2. #2
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    Quote Originally Posted by SouthSideSlim03
    I am writing a script to allow users to upload images and videos. In order not to take up alot of space or bandwidth I have decided to resize the images/videos to a smaller size. Once they are resized I will then save them to a database on my server.

    Here's the big question...

    When a query is called for these images/videos I want to resize them to their original size. Will this cause my pages to load slower and will this use more memory and processor resources with every page view due to the resize computation?

    Thanks in advance...
    Ok - loading slower, using more memory, and processor - yes it will do. Do not store static files in the database.

    Store them on the file system. That way when a request is made, your server does not have to execute PHP, then connect, query (which will grab from the file system anyway*), return a resultset, then output through php & apache.

    Outputting them as static files via apache / lighttpd will save you alot of CPU / memory compared to storing in the database.


    FFMpeg is a nice tool for resizing / re-encoding video as well, if you have not seen it before.

  3. #3
    Join Date
    Oct 2006
    Location
    Houston, TX
    Posts
    6
    If I uploaded the files to a file directory instead of the database would I be able to add variables such as timestamp and user who uploaded?

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    timestamp should be a function of the file system.. however there is no reason why you cnat store information in the DB alongside the pointer to the file, or you could store the file as <userid><filename>

    its up to you.
    you could even store the timestamp of the file int he db, and check to see that the stored timestamp mathces the actual timestamp.. that way round you have a security check to make sure the file retrieved is the same as the file stored
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    healdem has a point, but depending on how large / busy your site is I would suggest not checking this information at every file load, as it is just another - usually pointless call - assuming the users a) don't change their files that often and b) they have to upload new ones / updates through your software (i.e. you will know its been changed)

    When the user uploads the file, store it somewhere sensible, and add an entry with details about the file to a database table (md5 hash, filename, timestamp, etc)...

    When you view the page of the users photos, you can find all their pictures from the db table - show when they were uploaded etc, and still have the static files as I suggested.

    If for some reason you needed to check the file for security reasons, I'd suggest using md5 to hash the file, to verify its content has not changed - rather than time stamping.



    This makes a good read and points out exactly why you should never normally serve images from a db (I can't think of any compelling reason too, are there any?):

    http://mysqldump.azundris.com/archiv...-Database.html
    Last edited by rhs98; 11-30-06 at 17:10.

  6. #6
    Join Date
    Oct 2006
    Location
    Houston, TX
    Posts
    6
    Thanks guys! This was all good information...I don't know what compelled me to store the photos and videos into the db. The users will upload photos and images. They will rarely be updating them. The photos and videos will be dislpayed for other users on the site to view and play. I was just trying to minimize user of the disk space from my host.

    Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •