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:
After adding the watermark image to the source image, the destination image will look like the following, with the watermark image center aligned.
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