Get Image attributes from BLOB

Q: How can I obtain image attributes such as height, width, format from BLOB column?
A: Using Oracle Multimedia ORDImage object type it is possible to get such attributes.

Consider the following example:
DECLARE
  lv_blob                  BLOB;
  unused_attributes        CLOB;
  img_mimetype             VARCHAR2(32);
  img_width                INTEGER;
  img_height               INTEGER;
  img_contentlength        INTEGER;
  unused_fileformat        VARCHAR2(32);
  unused_contentformat     VARCHAR2(32);
  unused_compressionformat VARCHAR2(32);
BEGIN
  SELECT blob_content
  INTO lv_blob
  FROM mytable;
  ordsys.ordimage.getproperties(lv_blob,
                                unused_attributes,
                                img_mimetype,
                                img_width,
                                img_height,
                                unused_fileformat,
                                unused_compressionformat,
                                unused_contentformat,
                                img_contentlength);
  dbms_output.put_line('Width=' || img_width || ' Height=' || img_height);
END;

You may encounter exceptions while calling this procedure if the image format is not proper. So always wrap this procedure call within an EXCEPTION block and determine the error.

For a list of exceptions which you can handle, check out the documentation.

No comments :

Post a Comment