Skip to main content

Add Image as Watermark to Source Image using Oracle Multimedia


Requirement: The objective is to add an image as watermark to source image which is stored an Oracle database.

What is the purpose of a watermark on a image?

Using watermarks will prevent anyone (even your competitors) from making use of your images. If you implement them, it will help you protect your work and discourage anyone who wants to use your image to promote their project or business from doing so without your permission.

What is Oracle Multimedia ORD_IMAGE PL/SQL Package?

Oracle Multimedia provides the ORD_IMAGE PL/SQL package. This package provides functions and procedures to perform common operations such as importing and exporting image data to and from operating system files, extracting metadata from and writing metadata to image data, generating thumbnail images, and converting the format of image data.

This package adds Oracle Multimedia support to image data stored in BLOBs and BFILEs.

The following procedure (apply_image_watermark) will add an image as a watermark to the source image.

CREATE OR REPLACE PROCEDURE apply_image_watermark(
    p_document_id           IN NUMBER,
    x_return_status out nocopy  VARCHAR2,
    x_return_message out nocopy VARCHAR2)
AS
  source_image ordsys.ordimage;
  added_image ordsys.ordimage;
  dest_image ordsys.ordimage;
  properties ordsys.ord_str_list;
  LOGGING VARCHAR2(2000);
  ex_error exception;
BEGIN
  x_return_status := 'S';
  x_return_message := 'Process Completed...';
  
  IF (p_document_id IS NULL) THEN
      x_return_status := 'E';
      x_return_message := 'Document ID can not be blank..';
      raise ex_error;
  END IF;
 
 -- Get source blob, and convert to ORDImage
  BEGIN
    SELECT ordsys.ordimage(raw_document), ordsys.ordimage(raw_document)
      INTO source_image, dest_image
      FROM fxgn_documents
     WHERE document_id = p_document_id FOR UPDATE;
    exception
    WHEN no_data_found OR too_many_rows THEN
      x_return_message := 'Error deriving source image ['||sqlerrm||']';
      raise ex_error;
  END;
  
  BEGIN
    SELECT ordsys.ordimage(raw_document)
      INTO added_image
      FROM fxgn_documents
     WHERE document_id = 368642; -- Watermark Image
    exception
    WHEN no_data_found OR too_many_rows THEN
      x_return_message := 'Watermark image not found ['||sqlerrm||']';
      raise ex_error;
  END;
  
  -- specify properties
  properties := ordsys.ord_str_list(
                   'position=middlecenter', 
                   'transparency=0.3');
  
  -- add image watermark to source image
  source_image.applywatermark(added_image, dest_image, LOGGING, properties);
  
  -- Replace original image with dest image
  UPDATE fxgn_documents 
     SET raw_document = dest_image.getcontent()  
   WHERE document_id = p_document_id;
  
  COMMIT;

exception
  WHEN ex_error THEN
  ROLLBACK;
  x_return_status  := 'E';
  x_return_message := '[ERROR]'||x_return_message;
WHEN others THEN
  ROLLBACK;
  x_return_status  := 'E';
  x_return_message :='[ERROR]'||substr(1,100,sqlerrm);
END apply_image_watermark;

Calling the procedure (apply_image_watermark)

SET serveroutput ON;

DECLARE
  x_return_message VARCHAR2(4000);
  x_return_status  VARCHAR2(1);
BEGIN
  apply_image_watermark (:p_document_id,
                         x_return_status, 
                         x_return_message);
  
  IF x_return_status = 'E' THEN
    dbms_output.put_line (x_return_message);
  END IF;
END;

What is ORDSYS.ORDImage?

ORDSYS is the owner of all the interMedia code and default data. The OrdImage type decends from the OrdSource type which contains a BLOB that is used to store the image data.

Parameters

All image data are represented as ORDSYS.ORDImage.

source_image
The source image data.

added_image
The watermark image stored and this to be added to the source image.

dest_image
The destination image for the watermarked image.

logging
A string that contains information about any unexpected behavior that occurred during the watermarking operation. If the operation is successful, an empty string is returned. Otherwise, this procedure returns a string that describes the unexpected behavior.

properties
A string list of name-value pairs that define attributes of the watermark image, including: position, and transparency.

Exceptions

ORDImageExceptions.NULL_CONTENT

This exception is raised when the source image or added image is NULL.

ORDImageExceptions.NULL_DESTINATION

This exception is raised when the destination image BLOB is NULL.

Output:

Fig 1: Source Image

Fig 2: Watermark Image

After adding the watermark image to the source image, the destination image will look like the following, with the watermark image center aligned.

Fig 3: Destination Image

Note: Oracle Multimedia is no longer supported in Oracle Database 19.

References:

Comments

  1. Do you need financing to renovate your house or to carry out your various projects? Fast and reliable in the short and long term at a rate of 3%. For more details: contact us directly by financialserviceoffer876@gmail.com WhatsApp +918929509036

    ReplyDelete

Post a Comment

Popular posts from this blog

Printing Page Numbers in RTF Template [Oracle BI Publisher]

Here I am giving an example to print the page numbers dynamically in the RTF (Rich Text Format) template. Step 1:  Go to page footer and copy and paste the below script. Page |  <?fo:page-number?>  of  <?fo:page-number-citation:xdofo:lastpage-joinseq?> <fo:page-number> :   This is the object, which is used to represent the current page-number. <?fo:page-number-citation:xdofo:lastpage-joinseq?> :  This is the syntax, which is used to represent the total number of pages. Step 2:  Load the XML and preview the result. Output: That's it. References: fo:page-number Printing Page Number Code in Oracle XMLP RTF Template

Oracle Application Express Views (APEX)

Application Express Views Search SELECT * FROM apex_dictionary WHERE column_id = 0; View Comment Parent View APEX_APPLICATIONS Applications defined in the current workspace or database user. APEX_WORKSPACES APEX_APPLICATION_ALL_AUTH All authorization schemes for all components by Application APEX_APPLICATIONS ...

Save Selected Interactive Grid Records into a Collection - Oracle APEX

Here I am giving an example to save selected interactive grid records into a oracle apex collection. Step 1: Create a new blank page. Note: Mine was page 20. You will need to update reference to " P20 " with your page number if it's different. Step 2: Create a new interactive grid report region to the page using below query. Set Static Id "EmpDetails" to the region. SELECT  *     FROM   ( SELECT  emp . empno ,                emp . ename ,                emp . JOB ,                dept . dname department ,                dept . loc  LOCATION ,                mgr . ename  ...