Resize an image stored in a DB prior to diplaying it on page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bissatch@yahoo.co.uk

    Resize an image stored in a DB prior to diplaying it on page

    Hi,

    I have a collection of images stored in a DB. They are there for the
    purpose of a news system. When the user views the homepage it will
    diplay cropped versions of the news where the user will them click the
    'read more' link to view the entire article. It will also display a
    thumbnail of the article image. As the image is stored at its full
    display size in the DB I need to be able to resize it before outputing
    it.

    To display the image I use a PHP file called 'imageviewer.ph p' and pass
    the unique idetifier as a GET parameter. Once the correct image data
    column field has been queried I use the following line to output it
    within the <img> tag:


    echo pg_unescape_byt ea($imgdata); //PostgreSQL database


    However, in this instance I need to be able to resize it to a thumbnail
    image prior to outputting. How would I do this?

    Cheers

    Burnsy

  • bissatch@yahoo.co.uk

    #2
    Re: Resize an image stored in a DB prior to diplaying it on page


    bissatch@yahoo. co.uk wrote:[color=blue]
    > Hi,
    >
    > I have a collection of images stored in a DB. They are there for the
    > purpose of a news system. When the user views the homepage it will
    > diplay cropped versions of the news where the user will them click the
    > 'read more' link to view the entire article. It will also display a
    > thumbnail of the article image. As the image is stored at its full
    > display size in the DB I need to be able to resize it before outputing
    > it.
    >
    > To display the image I use a PHP file called 'imageviewer.ph p' and pass
    > the unique idetifier as a GET parameter. Once the correct image data
    > column field has been queried I use the following line to output it
    > within the <img> tag:
    >
    >
    > echo pg_unescape_byt ea($imgdata); //PostgreSQL database
    >
    >
    > However, in this instance I need to be able to resize it to a thumbnail
    > image prior to outputting. How would I do this?
    >
    > Cheers
    >
    > Burnsy[/color]

    Ok, not many replies. Can anybody tell me how this might be done with
    an image stored in a MySQL db if possible? Cheers

    Burnsy

    Comment

    • Steve

      #3
      Re: Resize an image stored in a DB prior to diplaying it on page

      [color=blue]
      > echo pg_unescape_byt ea($imgdata); //PostgreSQL database[/color]
      [color=blue]
      > However, in this instance I need to be able to resize it to a thumbnail
      > image prior to outputting. How would I do this?[/color]


      First <http://www.php.net/manual/en/function.imagec reatefromstring .php>
      then <http://www.php.net/manual/en/function.imagec opyresized.php> or
      <http://www.php.net/manual/en/function.imagec opyresampled.ph p>, then
      <http://www.php.net/manual/en/function.imagej peg.php>, and finally
      <http://www.php.net/manual/en/function.imaged estroy.php>.

      ---
      Steve

      Comment

      • NC

        #4
        Re: Resize an image stored in a DB prior to diplaying it on page

        bissatch@yahoo. co.uk wrote:[color=blue]
        >
        > I need to be able to resize it to a thumbnail image
        > prior to outputting. How would I do this?[/color]

        The easy answer is that you probably shouldn't do it at all.
        Image resizing is a CPU-intensive process, so resizing should
        be done once, when uploading the image to the server. The
        resulting thumbnail would then be stored next to the full-size
        image.

        Also, the wisdom of storing images in databases is questionable.
        If you have a PHP page with five images on it, every time someone
        views it, six simultaneous connections to the database will be
        opened.

        For details on resizing, see documentation for imagecopyresize d()
        and imagecopyresamp led() functions:




        Cheers,
        NC

        Comment

        • Default User

          #5
          Re: Resize an image stored in a DB prior to diplaying it on page

          Steve wrote:
          [color=blue]
          >[color=green]
          > > echo pg_unescape_byt ea($imgdata); //PostgreSQL database[/color]
          >[color=green]
          > > However, in this instance I need to be able to resize it to a
          > > thumbnail image prior to outputting. How would I do this?[/color]
          >
          >
          > First
          > <http://www.php.net/manual/en/function.imagec reatefromstring .php>
          > then <http://www.php.net/manual/en/function.imagec opyresized.php> or
          > <http://www.php.net/manual/en/function.imagec opyresampled.ph p>, then
          > <http://www.php.net/manual/en/function.imagej peg.php>, and finally
          > <http://www.php.net/manual/en/function.imaged estroy.php>.[/color]


          Some implementations won't have the JPEG support compiled in. There's
          sometimes a program on UNIX systems called convert that can do what's
          needed.





          Brian

          Comment

          • badr

            #6
            Re: Resize an image stored in a DB prior to diplaying it on page

            hi every body
            while i see alot of image functions in php but really i ever use one,

            bissa...@yahoo. co.uk

            i may adivse you to store 2 things :

            1- the path in the DB of the small and big images you may need one
            field the (image_path) and the add the big images path programatically .

            2- you need also to store the image or you may need to create your own
            uploade system to uploade the images (big and small), so you need to
            upload the image twice the (small & big).

            if you store the image in the DB in binary format i think it take a
            time to be load and if it is more than 100KB it may reduce the
            execution of your web page.

            check it

            Comment

            • Bugz

              #7
              Re: Resize an image stored in a DB prior to diplaying it on page

              A) You probably wouldn't want to store the image in th DB in the first
              place
              B) Since you've done that, save the image in the /tmp/ forlder after
              reading it from the DB, resize that image and display it on the page.
              C) If you plan on having lots of visualizations of the thumbnail,
              you'll most probably want to save the image for future use... do this
              by either :
              1 - updating the DB with a pointer to the resized image
              2 - Check if the file name of the thumbnail exists in a give Directory
              before processing the image.

              Preferably, you'd want to store a pointer in the DB of both the Thumb
              and the main image.This way, you transfer less data between PHP and
              MySQL, hence making your code quicker to execute.

              Comment

              Working...