Jump to content

Recommended Posts

Posted

Hi guys,

can someone give me a suggestion(maybe a sample code) on how to watermark an image with a specific transparent png that i already have?

the png is my logo and i want to add it to a set of images.

Just the basic help is needed - don't waste too much time on it.

Thank you kindly,

Mike

  • Solution
Posted

Then here is a basic example  :)

Func _Watermark($sFile2, $sFile, $sLogo)
    Local $hImage1, $hImage2, $hGraphic
    
    _GDIPlus_Startup ()
    $hImage1 = _GDIPlus_ImageLoadFromFile ($sFile)   ; image
    $X1 = _GDIPlus_ImageGetWidth ($hImage1)
    $Y1 = _GDIPlus_ImageGetHeight ($hImage1)
    $hImage2 = _GDIPlus_ImageLoadFromFile ($sLogo)  ; logo
    $X2 = _GDIPlus_ImageGetWidth ($hImage2)
    $Y2 = _GDIPlus_ImageGetHeight ($hImage2)
    
    $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1)
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hImage2, 0, $Y1-$Y2-30)  
    _GDIPlus_ImageSaveToFile ($hImage1, $sFile2)  ; image watermarked
    
    _GDIPlus_ImageDispose ($hImage1)
    _GDIPlus_ImageDispose ($hImage2)
    _GDIPlus_ShutDown ()
EndFunc   ;==>_Watermark
  • 5 years later...
Posted (edited)
  On 8/11/2014 at 10:36 AM, mikell said:

Then here is a basic example  :)

Func _Watermark($sFile2, $sFile, $sLogo)
    Local $hImage1, $hImage2, $hGraphic
    
    _GDIPlus_Startup ()
    $hImage1 = _GDIPlus_ImageLoadFromFile ($sFile)   ; image
    $X1 = _GDIPlus_ImageGetWidth ($hImage1)
    $Y1 = _GDIPlus_ImageGetHeight ($hImage1)
    $hImage2 = _GDIPlus_ImageLoadFromFile ($sLogo)  ; logo
    $X2 = _GDIPlus_ImageGetWidth ($hImage2)
    $Y2 = _GDIPlus_ImageGetHeight ($hImage2)
    
    $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1)
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hImage2, 0, $Y1-$Y2-30)  
    _GDIPlus_ImageSaveToFile ($hImage1, $sFile2)  ; image watermarked
    
    _GDIPlus_ImageDispose ($hImage1)
    _GDIPlus_ImageDispose ($hImage2)
    _GDIPlus_ShutDown ()
EndFunc   ;==>_Watermark
Expand  

Hi everybody, i want scale logo image before watermark it, how can i do ?

Edited by quimao
Posted
  On 6/17/2020 at 5:11 AM, quimao said:

i want scale logo image

Expand  

_GDIPlus_ImageScale.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted
  On 6/17/2020 at 9:26 AM, MrCreatoR said:
Expand  

Thank MrCreatoR

this is my code 

Func _Watermark($sOutput, $sSource, $sLogo)
    Local $hImage1, $hImage2, $hGraphic
    _GDIPlus_Startup ()
    $hImage1 = _GDIPlus_ImageLoadFromFile ($sSource)   ; image
    $X1 = _GDIPlus_ImageGetWidth ($hImage1)
    $Y1 = _GDIPlus_ImageGetHeight ($hImage1)
    $hImage2 = _GDIPlus_ImageLoadFromFile ($sLogo)  ; logo
    $X2 = _GDIPlus_ImageGetWidth ($hImage2)
    $Y2 = _GDIPlus_ImageGetHeight ($hImage2)

    If $X1 > $X2 Then
        $iScale = $X1/$X2
    ElseIf $Y1 > $Y2 Then
        $iScale = $Y1/$Y2
    Else
        $iScale = 1
    EndIf
    $hImage_Scaled = _GDIPlus_ImageScale($hImage2, $iScale, $iScale)
    $X3 = _GDIPlus_ImageGetWidth ($hImage_Scaled)
    $Y3 = _GDIPlus_ImageGetHeight ($hImage_Scaled)
;~  ConsoleWrite($X3&" "&$Y3)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage_Scaled, $X1/2-$X3/2,$Y1/2-$Y3/2)
    _GDIPlus_ImageSaveToFile($hImage1, $sOutput)  ; image watermarked
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_ImageDispose($hImage_Scaled)
    _GDIPlus_ShutDown ()
EndFunc   ;==>_Watermark

I change size of logo iamge and make it at center, but it seems it doesn't work. Sorry for my bad

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...