String bg_filename = "D: // temptest // bg.jpg ";
String original_filename_500 = NULL;
String watermark_filename = "D: // temptest // bokee.png ";
Final int mark_h = 15; // watermark height
Final int no_mark = 100; // The height or width of the image
Final int bokee_mark = 200; // The image width is 200
Final int has_mark = 300; // The image width is over 300.
Final int y_font = 10;
Try {
For (INT I = 1; I <= 18; I ++) {// I made 18 loops during the experiment.
Original_filename_500 = "D: // temptest //" + I + ". jpg ";
File file_500 = NULL;
Image IMG = NULL;
Magickimage mi_wm = NULL;
Try {
File_500 = new file (original_filename_500 );
IMG = ImageIO. Read (file_500 );
} Catch (exception e ){
System. Out. println ("can not open" + original_filename_500 + "500's photo ");
}
If (IMG! = NULL ){
Int width = IMG. getwidth (null );
Int Height = IMG. getheight (null );
If (width <= no_mark | height <= no_mark ){
System. Out. println (original_filename_500 + "no watermark ");
} Else {
Imgtools imag = new imgtools (width, height + mark_h, bg_filename );
Imag. makebigbyjmagickgb (bg_filename );
Imageinfo ii_orig = new imageinfo ();
Ii_orig.setfilename (bg_filename );
Magickimage mi_orig = new magickimage (ii_orig );
Imageinfo ii_wm_500 = new imageinfo ();
Ii_wm_500.setfilename (original_filename_500 );
Magickimage mi_wm_500 = new magickimage (ii_wm_500 );
Mi_orig.compositeimage (compositeoperator. addcompositeop, mi_wm_500, 0, 0 );
Mi_orig.setmagick ("jpg ");
Mi_orig.setcompression (compressiontype. Compression );
Final imageinfo ii_result = new imageinfo ();
Ii_result.setquality (90 );
If (width <= bokee_mark & width> no_mark ){
Drawinfo ainfo = new drawinfo (ii_orig );
Ainfo. setfill (pixelpacket. querycolordatabase ("gray "));
Ainfo. setopacity (0 );
Ainfo. setpointsize (9 );
Ainfo. setfont ("Arial ");
Ainfo. settextantialias (true );
Ainfo. settext ("http://www.fiten.com ");
Int x = (width-NO_MARK)/2;
Int y = height + y_font;
Ainfo. setgeometry ("+" + x + "+" + Y + "");
Mi_orig.annotateimage (ainfo );
} Else if (width> bokee_mark & width <= has_mark ){
Drawinfo ainfo = new drawinfo (ii_orig );
Ainfo. setfill (pixelpacket. querycolordatabase ("gray "));
Ainfo. setopacity (0 );
Ainfo. setpointsize (9 );
Ainfo. setfont ("Arial ");
Ainfo. settextantialias (true );
String domain = "manzhouyexing02 ";
Ainfo. settext (http://www.fiten.com /);
Int x = (width-(110 + (5 * domain. Length ()-1)/2;
Int y = height + y_font;
Ainfo. setgeometry ("+" + x + "+" + Y + "");
Mi_orig.annotateimage (ainfo );
} Else if (width> has_mark ){
Imageinfo ii_wm = new imageinfo ();
Ii_wm.setfilename (watermark_filename );
Mi_wm = new magickimage (ii_wm );
Mi_orig.compositeimage (compositeoperator. addcompositeop, mi_wm, 1, height );
Drawinfo ainfo = new drawinfo (ii_orig );
Ainfo. setfill (pixelpacket. querycolordatabase ("gray "));
Ainfo. setopacity (0 );
Ainfo. setpointsize (9 );
Ainfo. setfont ("Arial ");
Ainfo. settextantialias (true );
String domain = "manzhouyexing02 ";
Ainfo. settext (http://www.fiten.com /);
Int x = width-105-(5 * domain. Length ()-1)-8;
Int y = height + y_font;
Ainfo. setgeometry ("+" + x + "+" + Y + "");
Mi_orig.annotateimage (ainfo );
}
Mi_orig.setfilename ("D: // temptest //" + I + "_" + 1 + ". jpg ");
Mi_orig.writeimage (ii_result );
Mi_orig.destroyimages ();
If (width> has_mark) mi_wm.destroyimages ();
}
}
}
} Catch (magickexception me ){
Me. printstacktrace ();
}
System. Exit (0 );}