3 Replies Latest reply: Mar 30, 2011 9:53 AM by Yann39 RSS

    How to show an ORDImage thumbnail without storing it ?

    Yann39
      Hi,

      I'm using Oracle 10g r2.

      I need to show ORDImages (and BLOBs).

      Here is my procedure that shows thumbnails :
      create or replace procedure show_photo_thumbnail(v_id_photo in number, v_height in number, v_width in number) as
           obj ordsys.ordimage;
           obj2 ordsys.ordimage;
      begin
           --obj2 := ordsys.ordimage.init();
           select phot_source into obj from photos where phot_id = v_id_photo;
           select phot_source into obj2 from photos where phot_id = v_id_photo for update;
           obj.processcopy('maxscale= '||v_width||' '||v_height, obj2);
           owa_util.mime_header(nvl(obj2.getmimetype(),'application/octet'), false );
           htp.p('content-length: ' || obj2.getcontentlength());
           htp.p('content-disposition: filename="' || obj2.source.srcname || '"');
           owa_util.http_header_close;
           wpg_docload.download_file(obj2.source.localdata);
           commit;
      end;
      It works, but if I call this function repeatedly (from our apex application), the image quality becomes less and less good, it seems it processes always the same image.
      And for example if I call show_photo_thumbnail(1126, 150, 150) and then show_photo_thumbnail(1126, 500, 500), it seems the 500 x 500 image is processed from the 150 x 150 thumbnail so the quality is very poor.

      I read the entire documentation and I really don't understand why.

      By calling this other procedure we can see that the content stored stay unchanged :
      procedure show_photo_infos(v_id_photo in number, v_height in number, v_width in number) as
           obj ordsys.ordimage;
           obj2 ordsys.ordimage;
      begin
           select phot_source into obj from photos where phot_id = v_id_photo;
           select phot_source into obj2 from photos where phot_id = v_id_photo for update;
           obj.processcopy('maxscale= '||v_width||' '||v_height, obj2);
           dbms_output.put_line('obj  : '||obj.getmimetype()||', '||obj.getcontentlength()||' bytes, '||obj.getwidth()||' x '||obj.getheight());
           dbms_output.put_line('obj2 : '||obj2.getmimetype()||', '||obj2.getcontentlength()||' bytes, '||obj2.getwidth()||' x '||obj2.getHeight());
      end;
      
      show_photo_infos(1126, 200, 200);
      obj  : image/jpeg, 79754 bytes, 572 x 504
      obj2 : image/jpeg, 4635 bytes, 200 x 176
      Any help would be much appreciated.

      Thanks.

      Yann.
        • 1. Re: How to show an ORDImage thumbnail without storing it ?
          Yann39
          Using BLOB, it works ...
          create or replace procedure show_photo_thumbnail(v_id_photo in number, v_height in number, v_width in number) as
               obj blob;
               obj2 blob;
          begin
               select p.phot_source.source.localdata into obj from photos p where p.phot_id = v_id_photo for update;
               ordimage.processcopy(obj,'maxscale= '||v_width||' '||v_height, obj2);
               wpg_docload.download_file(obj2);
          end;
          If one day someone can explain why it don't works using ordimage, please let me know.

          Thanks.

          Yann.
          • 2. Re: How to show an ORDImage thumbnail without storing it ?
            mannamal
            It should work exactly the same for ORDimage and BLOBs, as ORDImage stores and updates the image content in a BLOB attribute.

            The difference you are seeing might be because of which object you are reading. In the first example, obj2 was selected for update, but obj1 was not. So the local variable obj1 had the old data which was printed out, and this was different from the data in obj2, which had the changes that were updated in the table.

            If you don't want to persist the updated image, then you can select for update, make changes as you are currently, but then rollback at the very end (after you download the content). Then the original image will be retained in the table and changes you made in this transaction will be discarded. The next time you run the procedure you will be operating on the original image.

            I also notice you have a commit in the very first code snippet but not later. Depending on your logging settings that might be having an impact as well.
            • 3. Re: How to show an ORDImage thumbnail without storing it ?
              Yann39
              Thank you for information.