2 Replies Latest reply: Jun 26, 2013 7:24 AM by Karthick_Arp RSS

    Calculating size of Image

    Raunaq

      Guys ,

       

      I have a column in a table which stores an image?

       

      I want to calculate the size of the image?

       

      Any suggestions?

        • 1. Re: Calculating size of Image
          BluShadow

          That's impossible to answer.

           

          There are many different image formats each with their own way of storing the image data, some with compression, and some with varying levels of compression etc.  The actual data size can vary greatly regardless of the actual pixel dimensions of the picture.

           

          You also haven't provided any details about exactly what you are trying to achieve.

           

          Read the FAQ: Re: 2. How do I ask a question on the forums?

          • 2. Re: Calculating size of Image
            Karthick_Arp

            Use DBMS_LOB.GETLENGTH

             

            SQL> !ls -lrt |tail -2
            -rw-r--r--   1 karthick  staff    10395071 Jun 26 07:38 test.pdf
            -rw-r--r--   1 karthick  staff        3004 Jun 26 07:46 imagesCA37MMZX.jpg

            SQL> declare
              2      l_blob    blob;
              3      l_bfile    bfile;
              4  begin
              5      insert into t (id, val) values ( 1, empty_blob()) returning val into l_blob;
              6      l_bfile := bfilename( 'KARDIR', 'imagesCA37MMZX.jpg' );
              7      dbms_lob.fileopen    ( l_bfile );
              8      dbms_lob.loadfromfile( l_blob, l_bfile, dbms_lob.getlength( l_bfile ) );
              9      dbms_lob.fileclose   ( l_bfile );
            10      insert into t (id, val) values ( 2, empty_blob()) returning val into l_blob;
            11      l_bfile := bfilename( 'KARDIR', 'test.pdf' );
            12      dbms_lob.fileopen    ( l_bfile );
            13      dbms_lob.loadfromfile( l_blob, l_bfile, dbms_lob.getlength( l_bfile ) );
            14      dbms_lob.fileclose   ( l_bfile );
            15      commit;
            16  end;
            17  /

            PL/SQL procedure successfully completed.

            SQL> select id, dbms_lob.getlength(val) size_byte
              2    from t;

                    ID  SIZE_BYTE
            ---------- ----------
                     1       3004
                     2   10395071

             

            Message was edited by: Karthick_Arp

            Added a jpg file as well in the table