Hello there,

I'm adding pictures into a database, and I can get it out of it again. The date it saved as longblob.

When I show the picture, I did it with this:
Header( "Content-type: image/pjpeg");
echo($picture);

It works too, but I want to know the size of the picture t! How did I do that? I want it as the x-size and y-size!

thanks !

    I see the commando in the manual to PHP, but PHP don't understand them.. I think I need a libery, but there may be a easier way to do it. I have the file picture.php?id=1 as a picture, but cannot write the size of it, like it was a normally picture.

      a) Pursue libries if you need them

      or

      b) Don't give the images any size in the HTML

      or

      c) Record the image dimensions in columns in the table - although if you cant get a, then you will probably have to manually type the dimensions in when you are putting the images into the database. There are JavaScript solutions, however the imahe needs to be in the window somewhere... document.images[0].width

      Good luck.

        Ohh, I think, I will use Javascript. Can you tell me what I need to write in javascript? I want a variable in java to be the width of the picture called picture.php. I can by myself move the variable into php.

        Thanks!

          This is how I think you would have to do it then:

          1) Upload the pic
          2) Return the pic in a page which actually displays in a browser, and then uses JavaScript to find out the proportions, then submits itself to another PHP form which places the image dimensions into the row.

          So... have the form which you use to upload the pic to the database as normal.

          Then your upload script would look something like this:

          <?php
          if (!$pic){
          // they have not selected a pic to upload
          } else {
          
          // put the actual uploading bits here
          
          // you are going to have to get the primary key back for the image just uploaded
          // store it as $pkey or something
          
          
          
          //now we make the next page that gets the dimensions, and submits them
          
          ?>
          
          <html>
          <head>
          <title>Processing...</title>
          <script language="JavaScript">
          <!--
          function getDims() {
          var picwidth = document.images[0].width;
          var picheight = document.images[0].height;
          var varstring = "picwidth=" + picwidth + "&picheight=" + picheight + "&pkey="<?php echo $pkey; ?>";
          document.location = "submitdims.php?" + varstring;
          }
          -->
          </script>
          </head>
          <body onload="getDims()">
          <img src="picture.php?id=<?php echo $pkey; ?>">
          </body>
          </html>
          
          <?php
          }
          ?>
          
          

          Then you need to have submitdims.php which just has sometyhing like this (plus all your connection info!) :

          $sql = "UPDATE pics SET picwidth='$picwidth',picheight='$picheight' WHERE picid='$pkey'";
          $result = mysql_query($sql);
          

          Umm... Ok?

          Hopefully you can follow this 🙂

            I still have to ask though:
            Why don't you just not worry about the size of the image, because if you just put

            <img src="picture.php?id=334">

            It will place the picture on the page at it's original size.

            Oh - and in the page that has the image displayed in it, you will need to do a quick query of teh database to get the dimensioins back, then do this

            <img src="picture.php?id=334" width="<?php echo $picwidth; ?>" height="<?php echo $picheight; ?>"

              Thank you! I have found out of it... I need the size of the picture, because I will resize it. I'm copying it to the server, and finding out the size on the file (it is easy!)

              // UQK.DK

                Write a Reply...