Directly share the source code? Phpfunctionadd_wm ($ nmw_water, $ src_file, $ output_file, $ x, $ y) {if (file_exists ($ output_file) return; $ w1 = MagickGetImageWidth ($ nmw_water
Share source code directly
-
- 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. '/'. $ file, $ output_dir. '/'. $ file, $ arr );
- } Else {
- If (! Array_key_exists ($ to_dir. '/'. $ file, $ arr )){
- Continue;
- }
- $ Sub_arr = $ arr [$ to_dir. '/'. $ file];
- If ($ sub_arr ){
- $ X = intval ($ sub_arr [0]);
- $ Y = intval ($ sub_arr [1]);
- Add_wm ($ nmw_water, $ to_dir. '/'. $ file, $ output_dir. '/'. $ file, $ x, $ y );
- }
- }
- }
- }
- $ Dp-> close ();
- }
- $ To_dir = './resized ';
- $ Output_dir = './output ';
- // This is the coordinate array (posX, posY) of the area that matches the trousers color obtained by traversing image pixels using java ImageIO)
- $ Arr = array (
- Array (50, 50)
- );
- $ Water = './water.png ';
- $ Nmw_water = NewMagickWand ();
- MagickReadImage ($ nmw_water, $ water );
- Add_wm_recurse ($ nmw_water, $ to_dir, $ output_dir, $ arr );
- DestroyMagickWand ($ nmw_water );
- ?>