Oracle MultiMedia Image
Version 12.2

General Information
Library Note Morgan's Library Page Header
Which has the higher priority in your organization: Deploying a new database or securing the ones you already have? Looking for a website, and resources, dedicated solely to securing Oracle databases? Check out DBSecWorx.
Purpose Multimedia Image is a multi-object capability built into the Oracle Database that contains native APIs for storing, retrieving, and collecting metadata for in-database stored image files.
ordsys.ORDImage Columns
Column Name Data Type
SOURCE ordsys.ORDSOURCE
HEIGHT NUMBER(38)
WIDTH NUMBER(38)
CONTENTLENGTH NUMBER(38)
FILEFORMAT VARCHAR2(4000)
CONTENTFORMAT VARCHAR2(4000)
COMPRESSIONFORMAT VARCHAR2(4000)
MIMETYPE VARCHAR2(4000)
ordsys.ORDImage Methods
applyWatermark() image getHeight( ) ordImage()
applyWatermark() text getMetadata() process()
checkProperties() getMimeType() processCopy()
clearLocal() getProperties() processSourceCommand()
closeSource() getSource() putMetadata()
copy() getSourceLocation() readFromSource()
deleteContent() getSourceName() setLocal()
export getSourceType() setMimeType()
getBFile() getUpdateTime() setProperties()
getCompressionFormat() getWidth() setProperties()
getContent() import() setSource()
getContentFormat() importFrom() setUpdateTime()
getContentLength() init() trimSource()
getDICOMMetadata() isLocal() writeToSource()
getFileFormat() openSource()  
ordsys.ORDSource Columns
Column Name Data Type
LOCALDATA BLOB
SRCTYPE VARCHAR2(4000)
SRCLOCATION VARCHAR2(4000)
SRCNAME VARCHAR2(4000)
UPDATETIME DATE
LOCAL NUMBER
Required Schemas
ORDPLUGINS ORDSYS SI_INFORMTN_SCHEMA
Source {$ORACLE_HOME}/ord/im/admin

ordipksp.sql

ordsys.ORDImageConstants (package header)
ordsys.ORDImg_Pkg (package)
ordsys.ORDImgExtCodec_Pkg
ordsys.OrdImageSignature (type)
ordsys.ORDImage (type) - ordispec.sql
ordsys.ORDImageExceptions (pkg) - ordispec.sql (pkg header of exceptions)
Required System Privileges GRANT create any directory TO <schema_name>;
conn sys@pdbdev as sysdba

GRANT create any directory TO uwlass;
Sample Image Files Click here to download demo1.jpg
Click here to download demo2.png
For the demo on this page copy demo.jpg to c:\temp or if on a real operating system to $HOME and make the appropriate change to the CREATE DIRECTORY DDL below.
Right click on the images when they are displayed and select [Save Image As] or its equivalent in your browser.
 
MultiMedia Image Demo
Actions as SYS conn / as sysdba

ALTER USER ordsys ACCOUNT UNLOCK IDENTIFIED BY ordsys;
GRANT create session TO ordsys;


-- if an application schema does not already exist
conn sys@pdbdev as sysdba

CREATE USER uwclass
IDENTIFIED BY uwclass
DEFAULT TABLESPACE uwdata
TEMPORARY TABLESPACE temp
QUOTA 0 ON SYSTEM
QUOTA UNLIMITED ON uwdata;

GRANT create session TO uwclass;
GRANT create any directory TO uwclass;
GRANT create table TO uwclass;
OrdImage Methods conn uwclass/uwclass@pdbdev

CREATE OR REPLACE DIRECTORY imagedir AS 'c:\temp';

-- verify required objects are visible to schema
SELECT owner, object_name, object_type, status
FROM all_objects
WHERE object_name LIKE 'ORD%IM%G%'
AND owner NOT IN ('OE', 'IX')
ORDER BY 1,2;

desc dba_type_methods

col method_name format a30

SELECT method_name, COUNT(*)
FROM dba_type_methods
WHERE type_name = 'ORDIMAGE'
GROUP BY method_name
ORDER BY 1;


conn ordsys/ordsys@pdbdev

set linesize 141
col owner format a7
col agent format a6
col library_name format a15
col file_spec format a58
col leaf_filename format a15

desc all_libraries

SELECT *
FROM all_libraries;

-- explore what ordimage is
SELECT object_name, object_type
FROM user_objects
WHERE object_name = 'ORDIMAGE';

SELECT DISTINCT object_name
FROM user_arguments
WHERE package_name = 'ORDIMAGE'
ORDER BY 1;


conn uwclass/uwclass@pdbdev

CREATE TABLE t_image (
img_id NUMBER,
image  ordsys.ordimage);

desc t_image

set describe depth all linenum on indent on

desc t_image

-- create initial records
INSERT INTO t_image VALUES (1, ordsys.ordimage.init());
INSERT INTO t_image VALUES (2, ordsys.ordimage.init());
COMMIT;

SELECT * FROM t_image;

set serveroutput on

-- set all attributes
-- be sure that you have saved the files demo1.jpg and demo2.png
-- to the directory IMAGEDIR created above first

DECLARE
 obj ordsys.ordimage;
 ctx RAW(4000) := NULL;
BEGIN
  SELECT image
  INTO obj
  FROM t_image
  WHERE img_id = 1
  FOR UPDATE;

  obj.setSource('FILE', 'IMAGEDIR', 'demo1.jpg');
  -- import data
  obj.import(ctx);
  -- set image attributes in the IMAGE column metadata
  obj.setProperties;

  UPDATE t_image
  SET image = obj
  WHERE img_id = 1;

  SELECT image
  INTO obj
  FROM t_image
  WHERE img_id = 2
  FOR UPDATE;

  obj.setSource('FILE', 'IMAGEDIR', 'demo2.png');
  -- import data
  obj.import(ctx);
  -- set image attributes in the IMAGE column metadata
  obj.setProperties;

  -- checkProperties returns TRUE if the metadata matches the image
  IF obj.checkProperties() THEN
    dbms_output.put_line('TRUE');
  ELSE
    dbms_output.put_line('FALSE');
  END IF;

  UPDATE t_image
  SET image = obj
  WHERE img_id = 2;
END;
/

-- use SQL statements to access object metadata
col ImgCompression format a15

SELECT t.img_id, t.image.getCompressionFormat() ImgCompression
FROM t_image t;

col ImgFormat format a15

SELECT img_id, t.image.getContentFormat() ImgFormat
FROM t_image t;

col ByteSize format 9999999

SELECT t.img_id, t.image.getContentLength() ByteSize
FROM t_image t;

col FileType format a10

SELECT t.img_id, t.image.getFileformat() FileType
FROM t_image t;

col ImageSize format a20

SELECT t.img_id, t.image.getHeight() ||' x '|| t.image.getWidth() ||' pixels' ImageSize
FROM t_image t;

SELECT t.img_id, t.image.getMetadata() MetaData
FROM t_image t;

col MimeType format a20

SELECT t.img_id, t.image.getMimeType() MimeType
FROM t_image t;

col Src format a40

SELECT t.img_id, t.image.getSource() Src
FROM t_image t;

col SrcLocation format a15

SELECT t.img_id, t.image.getSourceLocation() SrcLocation
FROM t_image t;

col SrcName format a15

SELECT t.img_id, t.image.getSourceName() SrcName
FROM t_image t;

col SrcType format a15

SELECT t.img_id, t.image.getSourceType() SrcType
FROM t_image t;

SELECT t.img_id, t.image.getUpdatetime() UpdateTime
FROM t_image t;

-- display attributes using PL/SQL
set serveroutput on

DECLARE
 obj ordsys.ordImage;
 b   BLOB;
 c   CLOB;
 n1  NUMBER;
 n2  NUMBER;
 n3  NUMBER;
 v1  VARCHAR2(30);
 v2  VARCHAR2(30);
 v3  VARCHAR2(30);
 v4  VARCHAR2(30);
BEGIN
  SELECT image
  INTO obj
  FROM t_image
  WHERE img_id = 1;

  -- getContent Demo
  b := obj.getContent();
  dbms_output.put_line(dbms_lob.getlength(b));

  -- getProperties Overload 1 Demo taking as input the BLOB from getContent
  ordsys.ordImage.getProperties(b, c, v1, n1, n2, v2, v3, v4, n3);
  dbms_output.put_line('O1 C: ' || c);
  dbms_output.put_line('O1 V1: ' || v1);
  dbms_output.put_line('O1 N1: ' || n1);
  dbms_output.put_line('O1 N2: ' || n2);
  dbms_output.put_line('O1 V2: ' || v2);
  dbms_output.put_line('O1 V3: ' || v3);
  dbms_output.put_line('O1 V4: ' || v4);
  dbms_output.put_line('O1 N3: ' || n3);

  -- getProperties Overload 2 Demo taking as input the BLOB from getContent
  ordsys.ordImage.getProperties(b, c);
  dbms_output.put_line('O2 C: ' || c);
  dbms_output.put_line('O2 V1: ' || v1);

  -- getProperties Overload 3 and 4 mimic Overloads 1 and 2
  -- except they take a BFILE as input rather than a BLOB

END;
/
Apply Image Watermark DECLARE
 src_image ordsys.ordImage;
 add_image ordsys.ordImage;
 dst_image ordsys.ordImage;
 prop_tab  ordsys.ord_str_list;
 logging   VARCHAR2(2000);
 orig_size VARCHAR2(100);
 new_size  VARCHAR2(100);
BEGIN
  SELECT t.image
  INTO add_image
  FROM t_image t
  WHERE t.img_id = 1;

  SELECT t.image
  INTO src_image
  FROM t_image t
  WHERE t.img_id = 2;

  INSERT INTO t_image
  VALUES (3, ordsys.ordimage.init());

  SELECT t.image
  INTO dst_image
  FROM t_image t
  WHERE t.img_id = 3
  FOR UPDATE;

  -- specify properties
  prop_tab := ordsys.ord_str_list('position=bottomcenter', 'transparency=0.3');

  -- add image watermark to source image
  src_image.applyWatermark(add_image, dst_image, logging, prop_tab);

  UPDATE t_image t
  SET image = dst_image
  WHERE t.img_id = 3;

  dbms_output.put_line('Logging: ' || logging);

  SELECT t.image.getHeight() ||' x '|| t.image.getWidth() ||' pixels'
  INTO orig_size
  FROM t_image t
  WHERE t.img_id = 2;

  SELECT t.image.getHeight() ||' x '|| t.image.getWidth() ||' pixels'
  INTO new_size
  FROM t_image t
  WHERE t.img_id = 3;

  dbms_output.put_line(orig_size);
  dbms_output.put_line(new_size);
END;
/
Apply Text Watermark DECLARE
 src_image ordsys.ordImage;
 add_text  VARCHAR2(200) := 'Morgan''s Library ? 2011';
 dst_image ordsys.ordImage;
 prop_tab  ordsys.ord_str_list;
 logging   VARCHAR2(2000);
 orig_size VARCHAR2(100);
 new_size  VARCHAR2(100);
BEGIN
  SELECT t.image
  INTO src_image
  FROM t_image t
  WHERE t.img_id = 2;

  INSERT INTO t_image
  VALUES (3, ordsys.ordimage.init());

  SELECT t.image
  INTO dst_image
  FROM t_image t
  WHERE t.img_id = 3
  FOR UPDATE;

  -- specify properties
  prop_tab := ordsys.ord_str_list('font_name=Arial', 'font_style=bold', 'font_size=10',
              'text_color=blue', 'position_x=100', 'position_y=100', 'transparency=0.6');

  -- add image watermark to source image
  src_image.applyWatermark(add_text, dst_image, logging, prop_tab);

  UPDATE t_image t
  SET image = dst_image
  WHERE t.img_id = 3;

  dbms_output.put_line('Logging: ' || logging);

  SELECT t.image.getHeight() ||' x '|| t.image.getWidth() ||' pixels'
  INTO orig_size
  FROM t_image t
  WHERE t.img_id = 2;

  SELECT t.image.getHeight() ||' x '|| t.image.getWidth() ||' pixels'
  INTO new_size
  FROM t_image t
  WHERE t.img_id = 3;

  dbms_output.put_line(orig_size);
  dbms_output.put_line(new_size);
END;
/

Related Topics
DICOM
Directories
Oracle MultiMedia Audio
Oracle MultiMedia Image
Setup
UTL_RAW
What's New In 21c
What's New In 23c

Morgan's Library Page Footer
This site is maintained by Dan Morgan. Last Updated: This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2023 Daniel A. Morgan All Rights Reserved
  DBSecWorx