Auto thumbnails

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

    Auto thumbnails

    Hi,

    [crossposted]

    I'm putting together a website for a local estate agent.

    One of the things they want to do is upload property
    descriptions/prices/etc. plus a picture of the property which is for
    sale.

    I'd like to generate thumbnails of the pictures automatically either
    once the data is uploaded (preferred) or when the relevant page is
    delivered to the browser. Server-side scripting will most likely be
    done in PHP.

    Is this possible?

    Lemming
    --
    Curiosity *may* have killed Schrodinger's cat.
    http://goldcrossdata.co.uk/ ICQ: 8647501
  • Jeffrey Silverman

    #2
    Re: Auto thumbnails

    On Mon, 20 Oct 2003 16:26:05 +0100, Lemming wrote:
    [color=blue]
    > Hi,
    >
    > [crossposted]
    >
    > I'm putting together a website for a local estate agent.
    >
    > One of the things they want to do is upload property
    > descriptions/prices/etc. plus a picture of the property which is for sale.
    >
    > I'd like to generate thumbnails of the pictures automatically either once
    > the data is uploaded (preferred) or when the relevant page is delivered to
    > the browser. Server-side scripting will most likely be done in PHP.
    >
    > Is this possible?[/color]

    Yes.

    For more info, look at
    GD functions -- can be built into PHP directly.
    ImageMagick
    NetPBM


    Both IM and NetPBM must be accessed using passtrhu(), exec(), system()
    or similar. NetPBM does the best job of manipulating images, IMO.
    --
    Jeffrey D. Silverman | jeffrey AT jhu DOT edu
    Johns Hopkins University | Baltimore, MD
    Website | http://www.wse.jhu.edu/newtnotes/

    Comment

    • Lemming

      #3
      Re: Auto thumbnails

      "Jeffrey Silverman" <jeffrey@jhu.ed u> wrote:
      [color=blue]
      >On Mon, 20 Oct 2003 16:26:05 +0100, Lemming wrote:
      >[color=green]
      >> I'd like to generate thumbnails of the pictures automatically either once
      >> the data is uploaded (preferred) or when the relevant page is delivered to
      >> the browser. Server-side scripting will most likely be done in PHP.
      >>
      >> Is this possible?[/color]
      >
      >Yes.
      >
      >For more info, look at
      > GD functions -- can be built into PHP directly.
      > ImageMagick
      > NetPBM
      >
      >
      >Both IM and NetPBM must be accessed using passtrhu(), exec(), system()
      >or similar. NetPBM does the best job of manipulating images, IMO.[/color]

      Excellent - many thanks.

      Lemming
      --
      Curiosity *may* have killed Schrodinger's cat.
      http://goldcrossdata.co.uk/ ICQ: 8647501

      Comment

      • Raptor

        #4
        Re: Auto thumbnails

        Lemming wrote:[color=blue]
        > Hi,
        >
        > [crossposted]
        >
        > I'm putting together a website for a local estate agent.
        >
        > One of the things they want to do is upload property
        > descriptions/prices/etc. plus a picture of the property which is for
        > sale.
        >
        > I'd like to generate thumbnails of the pictures automatically either
        > once the data is uploaded (preferred) or when the relevant page is
        > delivered to the browser. Server-side scripting will most likely be
        > done in PHP.
        >
        > Is this possible?
        >
        > Lemming[/color]

        There's a tutorial on creating thumbnails using GD linked to the front
        page of phpfreaks.com.

        --
        --
        Lynn Wallace http://www.xmission.com/~lawall
        "I'm not proud. We really haven't done everything we could to protect
        our customers. Our products just aren't engineered for security."
        --Microsoft VP in charge of Windows OS Development, Brian Valentine.

        Comment

        • Nathan

          #5
          Re: Auto thumbnails

          Raptor <me@attbi.com > wrote in message news:<3F941CFC. 1090303@attbi.c om>...[color=blue]
          > Lemming wrote:[color=green]
          > > Hi,
          > >
          > > [crossposted]
          > >
          > > I'm putting together a website for a local estate agent.
          > >
          > > One of the things they want to do is upload property
          > > descriptions/prices/etc. plus a picture of the property which is for
          > > sale.
          > >
          > > I'd like to generate thumbnails of the pictures automatically either
          > > once the data is uploaded (preferred) or when the relevant page is
          > > delivered to the browser. Server-side scripting will most likely be
          > > done in PHP.
          > >
          > > Is this possible?
          > >
          > > Lemming[/color]
          >
          > There's a tutorial on creating thumbnails using GD linked to the front
          > page of phpfreaks.com.
          >
          > --[/color]

          I made this one on my own.

          <?php
          function CheckUpload($fi lename)
          {
          $checkjpg = explode('.', $filename);
          if($checkjpg[1] == 'jpg' || $checkjpg[1] == 'JPG' || $checkjpg[1] ==
          'jpeg' || $checkjpg[1] == 'JPEG')
          {
          $size = getimagesize("/var/www/domains/factory8.com/r6/pics/uploaded/temp/$filename");
          if($size[0] <= '540' && $size[1] <= '600')
          {
          $size = filesize("/var/www/domains/factory8.com/r6/pics/uploaded/temp/$filename");
          if($size <= '102400')
          {
          if (!file_exists("/var/www/domains/factory8.com/r6/pics/uploaded/$filename"))
          {
          return TRUE;
          }
          else
          {
          die('Filename already exists.');
          return FALSE;
          }
          }
          else
          {
          die('File is greater than 100k');
          return FALSE;
          }
          }
          else
          {
          die('File resolution is to large');
          return FALSE;
          }
          }
          die('File must be a jpg, sorry.');
          return FALSE;
          }

          function createThumb($fi lename,$uid, $extension)
          {
          $x = '150';
          $y = '150';
          $location = 'pics/uploaded/thumbnails/'.$uid.'.'.$ext ension;
          $proportain = 1; //0 for no, 1 for yes
          if (!$image=getima gesize($filenam e))
          {
          return FALSE; //return false if there is no image to create from
          or it is not a image
          }
          else
          {
          if ($image['2'] == '1')
          {
          $im = imagecreatefrom gif ($filename);
          }
          else if ($image['2'] == '2')
          {
          $im = imagecreatefrom jpeg ($filename);
          }
          else
          {
          return FALSE; // return false if filetype is not of gif or
          jpeg
          }
          if ($proportain == 1)
          {
          if ($image[0]<$image[1])
          {
          $x = $y * ($image[0]/$image[1]);
          }
          else
          {
          $y = $x / ($image[0]/$image[1]);
          }
          }
          $newim = imagecreatetrue color($x, $y);
          ImageCopyResamp led($newim, $im, 0, 0, 0, 0, $x, $y, $image[0],
          $image[1]);
          imagejpeg($newi m, $location);
          imagedestroy ($im);
          imagedestroy ($newim);
          return TRUE;
          }
          }
          ?>


          --


          Uploading file...<br>
          <?php
          if($file_name !="")
          {
          copy ("$file", "pics/uploaded/temp/$file_name")
          or die("Could not copy file.");
          }
          else {die("No file specified.");}
          ?>
          Checking file...<br>
          <?php
          $checkfile = CheckUpload($fi le_name);
          ?>
          Putting in permanent place...<br>
          <?php
          copy("$file", "/var/www/domains/factory8.com/r6/pics/uploaded/$file_name");
          ?>
          Creating thumbnail file...<br>
          <?php
          $fileinfo = explode('.', "$file_name ");
          $thumbcreated = createThumb("pi cs/uploaded/$file_name","$f ileinfo[0]","$fileinf o[1]");
          ?>
          Adding to the random picture list...<br>
          <?php
          $dbconn = mysql_connect(" localhost", "username", "password") ;
          mysql_select_db ("factory8_com" );
          $addtodb = mysql_query("IN SERT INTO bikepics (filename, comment,
          owner, ipaddy) VALUES('$file_n ame', '$comment', '$owner',
          '$REMOTE_ADDR') ");
          mysql_close($db conn);
          ?>
          <b>Done!</b><br>
          <?php
          print("
          <img src='pics/uploaded/$file_name'><br ><img
          src='pics/uploaded/thumbnails/$file_name'>
          ");
          ?>

          --

          only bad part, is i forgot to delete the pictures in the temp
          directory. :-P

          Comment

          • Nathan

            #6
            Re: Auto thumbnails

            Raptor <me@attbi.com > wrote in message news:<3F941CFC. 1090303@attbi.c om>...[color=blue]
            > Lemming wrote:[color=green]
            > > Hi,
            > >
            > > [crossposted]
            > >
            > > I'm putting together a website for a local estate agent.
            > >
            > > One of the things they want to do is upload property
            > > descriptions/prices/etc. plus a picture of the property which is for
            > > sale.
            > >
            > > I'd like to generate thumbnails of the pictures automatically either
            > > once the data is uploaded (preferred) or when the relevant page is
            > > delivered to the browser. Server-side scripting will most likely be
            > > done in PHP.
            > >
            > > Is this possible?
            > >
            > > Lemming[/color]
            >
            > There's a tutorial on creating thumbnails using GD linked to the front
            > page of phpfreaks.com.
            >
            > --[/color]

            Oh, you can see a working example here.

            Comment

            Working...