Jump to content

Recommended Posts

Posted (edited)

I am trying to apply a watermark image to a digital photograph. The following code puts the two images together however the watermark (produced in Photoshop) layers over the image and is not transparent. I am familar with $GUI_BKCOLOR_TRANSPARENT which allows you to apply text to an image without masking the image. Can this be achieved with an image on image. This is the code thus far.

CODE
#include <A3LGDIPlus.au3>

Global $hImage1, $hImage2, $hGraphic

; Initialize GDI+ library

_GDIP_Startup()

; First Image

$hImage1 = _GDIP_ImageLoadFromFile("C:\IMG_0477.jpg")

;Second Image

$hImage = _GDIP_ImageLoadFromFile("C:\watermark.jpg")

; Draw one image in another

$hGraphics = _GDIP_ImageGetGraphicsContext($hImage1)

_GDIP_GraphicsDrawImage($hGraphics, $hImage, 1, 1)

; Save resultant image

_GDIP_ImageSaveToFile($hImage1, "C:\test.jpg")

; Clean up resources

_GDIP_ImageDispose($hImage1)

_GDIP_ImageDispose($hImage2)

; Shut down GDI+ library

_GDIP_ShutDown()

Help is always appreciated

Ant..

Edited by anixon
Posted

I am trying to apply a watermark image to a digital photograph. The following code puts the two images together however the watermark (produced in Photoshop) layers over the image and is not transparent. I am familar with $GUI_BKCOLOR_TRANSPARENT which allows you to apply text to an image without masking the image. Can this be achieved with an image on image. This is the code thus far.

CODE
#include <A3LGDIPlus.au3>

Global $hImage1, $hImage2, $hGraphic

; Initialize GDI+ library

_GDIP_Startup()

; First Image

$hImage1 = _GDIP_ImageLoadFromFile("C:\IMG_0477.jpg")

;Second Image

$hImage = _GDIP_ImageLoadFromFile("C:\watermark.jpg")

; Draw one image in another

$hGraphics = _GDIP_ImageGetGraphicsContext($hImage1)

_GDIP_GraphicsDrawImage($hGraphics, $hImage, 1, 1)

; Save resultant image

_GDIP_ImageSaveToFile($hImage1, "C:\test.jpg")

; Clean up resources

_GDIP_ImageDispose($hImage1)

_GDIP_ImageDispose($hImage2)

; Shut down GDI+ library

_GDIP_ShutDown()

Help is always appreciated

Ant..

Edit:

The above code sets the X and y position of the second image but not the height and width of that image.

By capturing part of the same image and layering it overitself I can in effect create a defacto watermark. A rectangle (not coded) around the partial second image completing the task.

Can anyone tell me how to control the size of the second image.

Ant..

Posted

Edit:

The above code sets the X and y position of the second image but not the height and width of that image.

By capturing part of the same image and layering it overitself I can in effect create a defacto watermark. A rectangle (not coded) around the partial second image completing the task.

Can anyone tell me how to control the size of the second image.

Ant..

I think that I have resolved most of the issues with this instalment. In the code 50% of the image is written over the origional in addition the code also creates a clone (defacto watermark at 100% opacity) captured from the origional image which is also written to the image in a series of diagonal rectangles to both actions to render the proof of the origional image invaluable.

Comments are always appreciated

Ant..

CODE
#include <A3LGDIPlus.au3>

Global $hImage1, $hImage2, $hGraphics, $i = 2

; Initialize GDI+ library

_GDIP_Startup()

;Images

$hImage1 = _GDIP_ImageLoadFromFile("C:\default.jpg")

$hImage2 = _GDIP_ImageLoadFromFile("C:\default.jpg")

;Calculate Width/Height

$hWidth = _GDIP_ImageGetWidth($hImage2)

$hHeight = _GDIP_ImageGetHeight($hImage2)

;Draw one image in another

$hGraphics1 = _GDIP_ImageGetGraphicsContext($hImage1)

_GDIP_GraphicsDrawImage($hGraphics1, $hImage2, $hWidth / 2, 0)

;Create Watermark Graphic

$hGraphic2 = _GDIP_ImageGetGraphicsContext($hImage1)

; Draw the Watermark and Frame

Do

_GDIP_GraphicsDrawImageRectRect($hGraphic2, $hImage2, 0, 0, $hWidth / 4, $hHeight / 4, ($hWidth / 10) * $i, ($hHeight / 10) * $i, $hWidth / 10, $hHeight / 10)

_GDIP_GraphicsDrawRect($hGraphics1, ($hWidth / 10) * $i, ($hHeight / 10) * $i, $hWidth / 10, $hHeight / 10)

$i = $i + 1

Until $i = 8

; Save resultant image

_GDIP_ImageSaveToFile($hImage1, "C:\image.jpg")

; Clean up resources

_GDIP_ImageDispose($hImage1)

_GDIP_ImageDispose($hImage2)

_GDIP_GraphicsDispose($hGraphics1)

_GDIP_GraphicsDispose($hGraphics2)

; Shut down GDI+ library

_GDIP_ShutDown()

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...