Share Source Code directly
- <? Php
- Function add_wm ($ nmw_water, $ src_file, $ output_file, $ x, $ y ){
- If (file_exists ($ output_file ))
- Return;
- $ W1 = MagickGetImageWidth ($ nmw_water );
- $ H1 = MagickGetImageHeight ($ nmw_water );
- $ Nmw = NewMagickWand ();
- MagickReadImage ($ nmw, $ src_file );
- // Adjust the default watermark position
- $ Lt_w = 50;
- $ Lt_h = 50;
- If ($ x = 0 ){
- $ W = MagickGetImageWidth ($ nmw );
- $ H = MagickGetImageHeight ($ nmw );
- $ X = $ w;
- $ Y = $ h;
- } Else {
- // Adjust according to the actual situation
- $ Lt_w = 30;
- $ Lt_h = 40;
- }
- MagickCompositeImage ($ nmw, $ nmw_water, MW_OverCompositeOp, $ x-$ w1-$ lt_w, $ y-$ h1-$ lt_h );
- MagickWriteImage ($ nmw, $ output_file );
- DestroyMagickWand ($ nmw );
- }
- // It's still groovy's eachFileRecurse easy to use.
- Function add_wm_recurse ($ nmw_water, $ to_dir, $ output_dir, $ arr ){
- $ Dp = dir ($ to_dir );
- While ($ file = $ dp-> read ()){
- If ($ file! =. & $ File! = ..){
- If (is_dir ($ to_dir./. $ file )){
- Mkdir ($ output_dir./. $ file );
- Add_wm_recurse ($ nmw_water, $ to_dir ./.