62 Star 523 Fork 208

小帅丶 / imagetool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

作者

💳感谢支持

三叔 https://gitee.com/zoy1985

感谢贡献代码

周维 https://gitee.com/bejson GIF压缩方法

关注码小帅获取最新功能更新

码小帅

       ├── cn.xsshome.imagetool            //包名
       ├── convert                               
       │       └── ImageToChar             //图片转字符图片、文本方法  
       ├── slideverifycode        
       │       └── SlideVerifyCodeGenerateUtil      //滑块验证码工具类代码       
       │       └── SlideVerifyCode         //滑块验证码对象   
       ├── util        
       │       └── AnimatedGifEncoder      //GIF所需工具类代码
       │       └── Base64Util              //图片数据转base64编码工具类     
       │       └── GifDecoder              //Gif图片处理工具类代码
       │       └── GifImageUtil            //GIF图片添加文字特效工具类代码  
       │       └── GongGeUtil              //九宫格图片处理工具类代码      
       │       └── LZWEncoder              //图片处理所需工具类代码
       │       └── MergeImageUtil          //图片特效合并工具类代码
       │       └── NeuQuant                //图片处理所需工具类代码
       │       └── PngColoringUtil         //透明图片增加背景色工具类代码
       │       └── RotateImageUtil         //图片旋转工具类代码
       │       └── ImageLosslessUtil       //图片无损保存工具类代码   
       │       └── MergeImageFontUtil      //图片文字合并工具类代码   
       │       └── ImageGrayUtil           //图片灰度处理工具类代码   
       │       └── ImageDPIHandleUtil      //修改图片DPI工具类代码(仅支持JPG)-基于com.sun.image.codec
       │       └── ImagePixelUtil          //像素风工具类代码
       │       └── ImageWaterMarkUtil      //图片增加水印工具类代码
       │       └── DoubleExposureUtil      //图片双重曝光工具类代码
       ├── zoom   
       └──     └── ImageHelper             //图片缩放工具类代码 

示例代码

public class Sample {
	public static void main(String[] args) throws Exception {
		ImageToChar.load("G:/phone.jpg", "F:/gif/woman.txt");//静态图片转字符保存为txt文件
		ImageToChar.loadGif("C:/Users/Administrator/Desktop/页面录屏显示.gif", "F:/gif/");//动图转为动态的字符图片
		BufferedImage bi = null;
		bi = ImageIO.read(new File("G:/body.jpg"));
        String bytePic = ImageToChar.txtToImageByBase64(bi);//静态图转字符 返回转换后图片的base64
        System.out.println(bytePic);
	}
}

透明图片增加背景色示例代码

    public static void main(String[] args) throws Exception{
        String image = "F:\\testimg\\1011.png";//原始图片路径
        String resultImage = "F:\\testimg\\10111700.jpg";//处理后保存的图片路径
        changePNGBackgroudColor(image,resultImage, Color.pink);//Color.pink 即图片背景颜色
    }

图片旋转示例代码

public class RotateSample {
    public static void main(String[] args) throws  Exception {
        long start = System.currentTimeMillis();
        BufferedImage src = ImageIO.read(new File("E:\\testimg\\glassess.png"));//原图片本地路径
        BufferedImage des = RotateImageUtil.rotateImage(src,20);//旋转的角度
        ImageIO.write(des, "png", new File("E:\\testimg\\glassess2.png"));//旋转后保存的图片
        long end = System.currentTimeMillis();
        System.out.println("开始时间:" + start+ "; 结束时间:" + end+ "; 总共用时:" + (end - start) + "(ms)");
    }
}

GIF图片加文字特效示例代码

    public static void main(String[] args) throws Exception {
        GifImageUtil gifImageUtil = new GifImageUtil();
        String imagesavePath  = "C:\\Users\\xiaoshuai\\Desktop";//图片保存路径
        String imagesaveName = String.valueOf(System.currentTimeMillis());//图片保存名称 不包含后缀名
        String image  = "C:\\Users\\xiaoshuai\\Desktop\\db.gif";//原始图片
        String result = gifImageUtil.gifAddText(imagesavePath,imagesaveName,"微软雅黑",25,Color.pink,image,"图片添加文字","测试一下","1234","4567");
        System.out.println(result);
    }

白底图片转换透明底图片示例代码

    public static void main(String[] args) {
        System.out.println(PngConvertUtil.transparentImg("F:/testimg/hand.jpg", "F:/testimg/hand2020.png"));
    }

增加水印示例代码

    public static void main(String[] args) {
        //水印图片在指定位置
        BufferedImage image1 =  ImageWaterMarkUtil.addImgWaterMark("F://testimg//water.png", "F://testimg//gjy2.jpg", 4);
        File file = new File("F:\\testimg\\2020082701.jpg");
        ImageIO.write(image1, "jpg", file);
        //文本水印 铺满图片
        BufferedImage image2 = ImageWaterMarkUtil.addFullTextWaterMark("F://testimg//gjy2.jpg","小帅丶代码");
        File file2 = new File("F:\\testimg\\2020082702.jpg");
        ImageIO.write(image2, "jpg", file2);
        //图片水印 铺满图片
        BufferedImage image3 = ImageWaterMarkUtil.addFullImgWaterMark("F://testimg//gjy2.jpg","F://testimg//water.png");
        File file3 = new File("F:\\testimg\\2020082703.jpg");
        ImageIO.write(image3, "jpg", file3);
    }

GIF图片加文字特效示例图

原始图

原始图

转换图

转换图

给图片指定区域增加矩形框

原始图

原始图

转换图

转换图

给透明图片增加背景图

    public static void main(String[] args) throws Exception{
        //最好保证宽或高一致  
        BufferedImage src = ImageIO.read(new File("F:\\testimg\\gjy2.jpg"));//背景图
        BufferedImage png = ImageIO.read(new File("F:\\testimg\\banner.png"));//透明图
        BufferedImage image = MergeImageUtil.mergePendant(src, png, 0, 0, 1);
        File file = new File("F:\\testimg\\banner320.jpg");//输出图片路径
        ImageIO.write(image, "jpg", file);
    }

原始图

透明图

透明图

背景图

背景图

效果图

效果图

给图片增加水印

原图

原图

文本内容

小帅丶代码

水印图片 点击空白即可看到png图片中的内容

水印图片

增加文本水印铺满图片

增加文本水印铺满图片

增加图片水印铺满图片

增加图片水印铺满图片

增加图片水印指定位置

增加图片水印指定位置

给图片增加文字(消除锯齿、无损保存处理后图)

public class FontImgMergeSample {
    /** 字体 */
    private static String FONT_FAMILY = "方正粗黑宋简体";
    /** 字体大小 */
    private static Integer FONT_SIZE = 88;
    /** 颜色 */
    private static Color FONT_COLOR = new Color(255,255,255);

    public static void main(String[] args) throws Exception{
        long startTime = System.currentTimeMillis();
        //原图本地路径、保存图的本地路径
        String sourcePath = "F:\\testfile\\testimg\\banner.jpg";
        String targetPath = "F:\\testfile\\testimg\\mergebanner.jpg";
        BufferedImage image = ImageIO.read(new File(sourcePath));
        //文本
        String content = "小帅测试代码";
        Graphics2D g = (Graphics2D) image.getGraphics();
        //填充文字 从左往右
        MergeImageFontUtil.setContentToImgLR(content, g, 100, 200,FONT_FAMILY,FONT_SIZE,FONT_COLOR);
        ImageLosslessUtil.saveLosslessImage(image, targetPath, ImageType.IMAGE_TYPE_JPG);
        System.out.println("总耗时"+(System.currentTimeMillis()-startTime));
    }
}

原图

原图

处理后的图片

处理后的图片

图片灰度处理

public static void main(String[] args) throws ImageTypeException, Exception {
    String sourcePath = "原图本地路径";
    String targetPath = "新图保存的本地路径";
    String imageSuffix = "jpeg";//图片保存格式
    //图片灰度处理 推荐
    BufferedImage bufferedImage = ImageGrayUtil.grayImage3ByteBGR(sourcePath);
    //图片灰度处理 纯黑
    //BufferedImage bufferedImage = ImageGrayUtil.grayImageByteGRAY(sourcePath);
    //无压缩保存图片
    ImageLosslessUtil.saveLosslessImage(bufferedImage,targetPath,imageSuffix);
}

原图

原图

处理后的图片 TYPE_BYTE_GRAY

处理后的图片

处理后的图片 TYPE_3BYTE_BGR

处理后的图片

百叶图

处理后的图片 处理后的图片

九宫格图

处理后的图片

像素风原图

原图图片

像素风处理后图

处理后的图片

MIT License Copyright (c) 2020 小帅丶 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🍬图片转字符图片工具类,支持 Gif 动画、图片合并、图片加水印、文字消除锯齿、图片无损保存、图片像素风、九宫格图、百叶图、双重曝光、修改图片DPI等图片处理其他工具类方法。详情请看README.md文件说明 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/xshuai/imagetool.git
git@gitee.com:xshuai/imagetool.git
xshuai
imagetool
imagetool
master

搜索帮助