GIF图片转换

本文介绍使用GIF4J Java库为GIF图片添加文字水印的方法。通过不同位置和透明度设置,展示了如何在GIF上应用平滑和覆盖连续的水印效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[url]http://security.iteye.com/blog/35023[/url]


2年前,我提供了一个GIF4J的可用版,GIF4J是一套针对gif操作的Java类库。
周末无聊,最终破解了Gif4J的"Eval Gif4j"。
import com.gif4j. * ;

import java.awt. * ;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;


public class GifImageWatermarkExample {

// Usage: java GifImageWatermarkExample [PathToGifImageToWatermark] (please be sure that the gif4j jar is in your CLASSPATH)
// By default the gif4j_logotype.gif as an example gif image is used
public static void main(String[] args) {
File gifImageFileToWatermark = null ;
if (args.length == 0 ) {
gifImageFileToWatermark = new File( " test.gif " );
} else
gifImageFileToWatermark = new File(args[ 0 ]);

// load and decode gif image
GifImage gifImage = null ;
try {
gifImage = GifDecoder.decode(gifImageFileToWatermark);
} catch (IOException e) {
e.printStackTrace();
System.exit( 1 );
}

// change out directory if it is necessary
File outputDir = new File( " . " + File.separator + " result " );
if ( ! outputDir.exists())
outputDir.mkdirs();

// create watermark image using TextPainter
TextPainter painter = new TextPainter( new Font( " Verdana " , Font.BOLD, 10 ));
painter.setOutlinePaint(Color.WHITE);
BufferedImage watermarkImage = painter.renderString( " david.turing " , true );

// create watermark
Watermark watermark = new Watermark(watermarkImage, Watermark.LAYOUT_TOP_LEFT, 0.2f );

// apply watermark
GifImage topLeftWatermarked = watermark.apply(gifImage, true );
// apply watermark smoothly
GifImage topLeftWatermarked_smoothly = watermark.apply(gifImage, true );

// change the watermark alignment
watermark.setLayoutConstraint(Watermark.LAYOUT_MIDDLE_CENTER);

// apply watermark
GifImage middleCenterWatermarked = watermark.apply(gifImage, false );
// apply watermark smoothly
GifImage middleCenterWatermarked_smoothly = watermark.apply(gifImage, true );

// change the watermark alignment
watermark.setLayoutConstraint(Watermark.LAYOUT_BOTTOM_RIGHT);

// apply watermark
GifImage bottomRightWatermarked = watermark.apply(gifImage, false );
// apply watermark smoothly
GifImage bottomRightWatermarked_smoothly = watermark.apply(gifImage, true );

// change the watermark alignment
watermark.setLayoutConstraint(Watermark.LAYOUT_COVER_CONSECUTIVELY);
// change the watermark transparency
watermark.setTransparency( 0.20f );

// apply watermark
GifImage coverConsWatermarked = watermark.apply(gifImage, false );
// apply watermark smoothly
GifImage coverConsWatermarked_smoothly = watermark.apply(gifImage, true );

// Save the results
try {
GifEncoder.encode(topLeftWatermarked, new File(outputDir, " topLeftWatermarked.gif " ));
GifEncoder.encode(topLeftWatermarked_smoothly, new File(outputDir, " topLeftWatermarked_smooth.gif " ));
GifEncoder.encode(middleCenterWatermarked, new File(outputDir, " middleCenterWatermarked.gif " ));
GifEncoder.encode(middleCenterWatermarked_smoothly, new File(outputDir, " middleCenterWatermarked_smooth.gif " ));
GifEncoder.encode(bottomRightWatermarked, new File(outputDir, " bottomRightWatermarked.gif " ));
GifEncoder.encode(bottomRightWatermarked_smoothly, new File(outputDir, " bottomRightWatermarked_smooth.gif " ));
GifEncoder.encode(coverConsWatermarked, new File(outputDir, " coverConsWatermarked.gif " ));
GifEncoder.encode(coverConsWatermarked_smoothly, new File(outputDir, " coverConsWatermarked_smooth.gif " ));
} catch (IOException e) {
e.printStackTrace();
}
}
}
下面是运行的结果:
topLeftWatermarked.gifmiddleCenterWatermarked.gif
coverConsWatermarked.gifbottomRightWatermarked_smooth.gif

破解的包放在我的UserGroup下载:
http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=29304&threadID=36395&messageID=214504
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值