Java之~ 上传 图片压缩,阿里图片压缩,图片旋转方法工具类
需要的jar
jai_codec-1.1.3.jar,jai_core-1.1.3.jar,simpleimage-1.2.0.jar,metadata-extractor-2.3.1.jar(旋转时的jar)
//图片工具类
package com.javajy.util;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import javax.imageio.ImageIO;
import javax.media.jai.PlanarImage;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import com.alibaba.simpleimage.ImageFormat;
import com.alibaba.simpleimage.ImageWrapper;
import com.alibaba.simpleimage.SimpleImageException;
import com.alibaba.simpleimage.render.CropParameter;
import com.alibaba.simpleimage.render.ScaleParameter;
import com.alibaba.simpleimage.render.WatermarkParameter;
import com.alibaba.simpleimage.render.WriteParameter;
import com.alibaba.simpleimage.render.ScaleParameter.Algorithm;
import com.alibaba.simpleimage.util.ImageCropHelper;
import com.alibaba.simpleimage.util.ImageDrawHelper;
import com.alibaba.simpleimage.util.ImageReadHelper;
import com.alibaba.simpleimage.util.ImageScaleHelper;
import com.alibaba.simpleimage.util.ImageWriteHelper;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.MetadataException;
import com.drew.metadata.exif.ExifDirectory;
import com.sun.image.codec.jpeg.*;
public class YasuoUtil {
/* @SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
String path = resizeFix("D:\\workspace/frshop/src/main/webapp/image/123.jpg", "D:\\workspace/frshop/src/main/webapp/image/456.jpg");
System.out.println(path);
System.out.println(path.substring(path.lastIndexOf("/") + 1));
System.out.println("结束:" + new Date().toLocaleString());
}*/
//--------------方法一----------------------
/**
* @param fileName 原图片路径
* @param postPath 存放的压缩图片路径
* @return
* @throws IOException
*/
public static String resizeFix(String fileName, String postPath) throws IOException {
String path = "";
//此处是用来处理上传图片旋转
int angel = getRotateAngleForPhoto(fileName);//旋转图片角度
fileName = rotatePhonePhoto(fileName, angel); //获取旋转后的图片
File file = new File(fileName);// 读入服务器文件
Image img = ImageIO.read(file); // 构造Image对象
int width = img.getWidth(null); // 得到源图宽
int height = img.getHeight(null); // 得到源图长
//把长跟宽等比缩小,大于1000就压缩
if (width > 1000 || height > 1000) {
int w = 500;
int h = 500;
if ((width >= 1000 && width < 3000) || (height >= 1000 && height < 3000)) {
w = (int) (width / 2);//w int 新宽度
h = (int) (height / 2);//h int 新高度
} else if ((width >= 3000 && width < 5000) || (height >= 3000 && height < 5000)) {
w = (int) (width / 3);//w int 新宽度
h = (int) (height / 3);//h int 新高度
} else if ((width >= 5000) || (height >= 5000)) {
w = (int) (width / 5);//w int 新宽度
h = (int) (height / 5);//h int 新高度
}
resize(img, w, h, postPath);//源宽度或长度大于1000的时候进行压缩图片
path = postPath;
} else {//图片宽高小于1000的时候显示原图
path = fileName;//路径
}
return path;
}
/**
* 强制压缩/放大图片到固定的大小
*
* @param w int 新宽度
* @param h int 新高度
*/
public static void resize(Image img, int w, int h, String postPath) throws IOException {
String path = "";
// SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的 优先级比速度高 生成的图片质量比较好 但速度慢
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
image.getGraphics().drawImage(img, 0, 0, w, h, null); // 绘制缩小后的图
// File destFile = new File("D:\\项目/链焙/图片/654.png");
File destFile = new File(postPath);
FileOutputStream out = new FileOutputStream(destFile); // 输出到文件流
// 可以正常实现bmp、png、gif转jpg
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image); // JPEG编码
out.close();
}
//----------------------------以下为阿里压缩 多种类型 方法二-------------------
/**
* 阿里巴巴 simpleimage 图片处理工具类 功能 等比例缩放 裁切 加水印 复合操作
*
*/
// public static String WATER_IMAGE_URL = "D:\\img\\watermark.png";//打水印
protected static ImageFormat outputFormat = ImageFormat.JPEG;
/* public static void main(String[] args) {
// 1.等比例缩放
scaleNormal("D:\\workspace/frshop/src/main/webapp/image/123.jpg", "D:\\workspace/frshop/src/main/webapp/image/456.jpg");
// 2.等比例缩放加水印
// scaleWithWaterMark("D:\\img\\src.jpg",
// "D:\\img\\scaleWithWaterMark.jpg",720, 1080);
// 3.缩放到指定宽度
// scaleWithWidth("D:\\123.png", "D:\\456.jpg",400);
// 4.缩放到指定高度
// scaleWithHeight("D:\\img\\src.jpg", "D:\\img\\scaleWithHeight.jpg",
// 600);
// 5.裁切成正方形
// Cut("D:\\img\\src.jpg", "D:\\img\\cut.jpg");
// 6.从中间裁切
// CutCenter("D:\\img\\src.jpg", "D:\\img\\cutCenter.jpg", 600,800);
// print(40,20, 4,2);
// print(20,40, 4,2);
// print(40,20, 4,3);
}*/
//等比例压缩(不剪裁)
public final static String scaleNormal(String src, String target) {
String path="";
File out = new File(target); // 目的图片
FileOutputStream outStream = null;
int angel = getRotateAngleForPhoto(src);//此处是用来处理上传图片旋转
src = rotatePhonePhoto(src, angel);
File in = new File(src); // 原图片路径
FileInputStream inStream = null;
try {
inStream = new FileInputStream(in);
ImageWrapper imageWrapper = ImageReadHelper.read(inStream);
int w = imageWrapper.getWidth();//原图宽
int h = imageWrapper.getHeight();//原图高
int width = 720;//新宽度
int height = 1080;//新高度
int cw=w, ch=h,x=0,y=0;
boolean isDeal=true;
if(height>h || width>w){
isDeal=false;
}else if((w - width)>(h-height)){
ch=h;
cw=(h*width)/height;
x=(w-cw)/2;
if(cw>h){
cw=w;
ch=(w*height)/width;
y=(h-ch)/2;
x=0;
}
}else if((w - width)<=(h-height)){
cw=w;
ch=(w*height)/width;
y=(h-ch)/2;
if(ch>h){
ch=h;
cw=(h*width)/height;
x=(w-cw)/2;
y=0;
}
}
System.out.println("x: "+x+" y" +y+"cw: "+cw+" ch"+ch+"");
if(isDeal){
// CropParameter cropParam = new CropParameter(x, y, cw, ch);// 裁切参数
// PlanarImage planrImage = ImageCropHelper.crop(imageWrapper.getAsPlanarImage(), cropParam);
// ScaleParameter scaleParam = new ScaleParameter(width, height, Algorithm.LANCZOS); // 缩放参数
// planrImage = ImageScaleHelper.scale(planrImage, scaleParam);
// imageWrapper = new ImageWrapper(planrImage);
// 1.缩放
ScaleParameter scaleParam = new ScaleParameter(w, h, Algorithm.LANCZOS); // 缩放参数
if (w < width) {// 如果图片宽和高都小于目标图片则不做缩放处理
scaleParam = new ScaleParameter(w, h, Algorithm.LANCZOS);
} else {
int newHeight = getHeight(w, h, width);
scaleParam = new ScaleParameter(width, newHeight + 1, Algorithm.LANCZOS);
}
PlanarImage planrImage = ImageScaleHelper.scale(imageWrapper.getAsPlanarImage(), scaleParam);
imageWrapper = new ImageWrapper(planrImage);
}
// 4.输出
outStream = new FileOutputStream(out);
String prefix = out.getName().substring(out.getName().lastIndexOf(".") + 1);
ImageWriteHelper.write(imageWrapper, outStream, outputFormat.getImageFormat(prefix), new WriteParameter());
if(!isDeal){
path = src;
}else {
path = target;
}
} catch (IOException e) {
e.printStackTrace();
} catch (SimpleImageException e) {
} finally {
IOUtils.closeQuietly(inStream); // 图片文件输入输出流必须记得关闭
IOUtils.closeQuietly(outStream);
}
System.out.println("原图-------"+src+"压缩--------"+target);
return path;
}
/**
*
* @param pInput
* @param pImgeFlag
* @return
* @throws Exception
*/
public static boolean isPicture(String pInput, String pImgeFlag) throws Exception {
if (StringUtils.isBlank(pInput)) {
return false;
}
String tmpName = pInput.substring(pInput.lastIndexOf(".") + 1, pInput.length());
String imgeArray[][] = {{"bmp", "0"}, {"dib", "1"}, {"gif", "2"}, {"jfif", "3"}, {"jpe", "4"}, {"jpeg", "5"}, {"jpg", "6"}, {"png", "7"}, {"tif", "8"},
{"tiff", "9"}, {"ico", "10"}};
for (int i = 0; i < imgeArray.length; i++) {
if (!StringUtils.isBlank(pImgeFlag) && imgeArray[i][0].equals(tmpName.toLowerCase()) && imgeArray[i][1].equals(pImgeFlag)) {
return true;
}
if (StringUtils.isBlank(pImgeFlag) && imgeArray[i][0].equals(tmpName.toLowerCase())) {
return true;
}
}
return false;
}
/**
* 等比例缩放 会裁切部分内容
*
* @param src
* @param target
* @param width
* @param height
*/
@SuppressWarnings("static-access")
public final static void scale(String src, String target, int width, int height) {
File out = new File(target); // 目的图片
FileOutputStream outStream = null;
File in = new File(src); // 原图片
FileInputStream inStream = null;
try {
inStream = new FileInputStream(in);
ImageWrapper imageWrapper = ImageReadHelper.read(inStream);
int w = imageWrapper.getWidth();
int h = imageWrapper.getHeight();
float w1= 0f, h1 = 0f;
float sp = (float) w / h;
float rp = (float) width / height;
if (sp > rp) {
w1 = (width * h) / (float)w;
h1 = width;
} else if(sp<rp){
h1 = (height * w) /(float) h;
w1 = width;
}else{
w1=width;
h1=height;
}
// 1.缩放
ScaleParameter scaleParam = new ScaleParameter((int)w1, (int)h1, Algorithm.LANCZOS); // 缩放参数
PlanarImage planrImage = ImageScaleHelper.scale(imageWrapper.getAsPlanarImage(), scaleParam);
imageWrapper = new ImageWrapper(planrImage);
// 4.输出
outStream = new FileOutputStream(out);
String prefix = out.getName().substring(out.getName().lastIndexOf(".") + 1);
ImageWriteHelper.write(imageWrapper, outStream, outputFormat.getImageFormat(prefix), new WriteParameter());
} catch (IOException e) {
e.printStackTrace();
} catch (SimpleImageException e) {
} finally {
IOUtils.closeQuietly(inStream); // 图片文件输入输出流必须记得关闭
IOUtils.closeQuietly(outStream);
}
}
/**
* 压缩图片到 指定尺寸,图片比目标图片小则不会变形(有水印)
*
* @param src
* @param target
* @param width
* @param height
*/
public final static void scaleWithWaterMark(String src, String target, int width, int height) {
File out = new File(target); // 目的图片
FileOutputStream outStream = null;
File in = new File(src); // 原图片
FileInputStream inStream = null;
try {
inStream = new FileInputStream(in);
ImageWrapper imageWrapper = ImageReadHelper.read(inStream);
int w = imageWrapper.getWidth();
int h = imageWrapper.getHeight();
int cw=w, ch=h,x=0,y=0;
boolean isDeal=true;
if(height>h||width>w){
isDeal=false;
}else if((w - width)>(h-height)){
ch=h;
cw=(h*width)/height;
x=(w-cw)/2;
if(cw>h){
cw=w;
ch=(w*height)/width;
y=(h-ch)/2;
x=0;
}
}else if((w - width)<=(h-height)){
cw=w;
ch=(w*height)/width;
y=(h-ch)/2;
if(ch>h){
ch=h;
cw=(h*width)/height;
x=(w-cw)/2;
y=0;
}
}
System.out.println("x: "+x+" y" +y+"cw: "+cw+" ch"+ch+"");
if(isDeal){
CropParameter cropParam = new CropParameter(x, y, cw, ch);// 裁切参数
PlanarImage planrImage = ImageCropHelper.crop(imageWrapper.getAsPlanarImage(), cropParam);
ScaleParameter scaleParam = new ScaleParameter(width, height, Algorithm.LANCZOS); // 缩放参数
planrImage = ImageScaleHelper.scale(planrImage, scaleParam);
imageWrapper = new ImageWrapper(planrImage);
}
// 3.打水印
// BufferedImage waterImage = ImageIO.read(new File(WATER_IMAGE_URL));
BufferedImage waterImage = ImageIO.read(new File("D:\\img\\watermark.png"));
ImageWrapper waterWrapper = new ImageWrapper(waterImage);
Point p =calculate(imageWrapper.getWidth(),imageWrapper.getHeight(),
waterWrapper.getWidth(), waterWrapper.getHeight());
WatermarkParameter param = new WatermarkParameter(waterWrapper, 1f,(int) p.getX(),(int) p.getY());
BufferedImage bufferedImage = ImageDrawHelper.drawWatermark(imageWrapper.getAsBufferedImage(), param);
imageWrapper = new ImageWrapper(bufferedImage);
// 4.输出
outStream = new FileOutputStream(out);
String prefix = out.getName().substring(out.getName().lastIndexOf(".") + 1);
ImageWriteHelper.write(imageWrapper, outStream, outputFormat.getImageFormat(prefix), new WriteParameter());
} catch (IOException e) {
e.printStackTrace();
} catch (SimpleImageException e) {
} finally {
IOUtils.closeQuietly(inStream); // 图片文件输入输出流必须记得关闭
IOUtils.closeQuietly(outStream);
}
}
/**
* 缩放到指定宽度 高度自适应
*
* @param src
* @param target
* @param width
*/
@SuppressWarnings("static-access")
public final static void scaleWithWidth(String src, String target, Integer width) {
File out = new File(target); // 目的图片
FileOutputStream outStream = null;
File in = new File(src); // 原图片
FileInputStream inStream = null;
try {
inStream = new FileInputStream(in);
ImageWrapper imageWrapper = ImageReadHelper.read(inStream);
int w = imageWrapper.getWidth();
int h = imageWrapper.getHeight();
// 1.缩放
ScaleParameter scaleParam = new ScaleParameter(w, h, Algorithm.LANCZOS); // 缩放参数
if (w < width) {// 如果图片宽和高都小于目标图片则不做缩放处理
scaleParam = new ScaleParameter(w, h, Algorithm.LANCZOS);
} else {
int newHeight = getHeight(w, h, width);
scaleParam = new ScaleParameter(width, newHeight + 1, Algorithm.LANCZOS);
}
PlanarImage planrImage = ImageScaleHelper.scale(imageWrapper.getAsPlanarImage(), scaleParam);
imageWrapper = new ImageWrapper(planrImage);
// 4.输出
outStream = new FileOutputStream(out);
String prefix = out.getName().substring(out.getName().lastIndexOf(".") + 1);
ImageWriteHelper.write(imageWrapper, outStream, outputFormat.getImageFormat(prefix), new WriteParameter());
} catch (IOException e) {
e.printStackTrace();
} catch (SimpleImageException e) {
} finally {
IOUtils.closeQuietly(inStream); // 图片文件输入输出流必须记得关闭
IOUtils.closeQuietly(outStream);
}
}
/**
* 缩放到指定高度,宽度自适应
*
* @param src
* @param target
* @param height
*/
public final static void scaleWithHeight(String src, String target, Integer height) {
File out = new File(target); // 目的图片
FileOutputStream outStream = null;
File in = new File(src); // 原图片
FileInputStream inStream = null;
try {
inStream = new FileInputStream(in);
ImageWrapper imageWrapper = ImageReadHelper.read(inStream);
int w = imageWrapper.getWidth();
int h = imageWrapper.getHeight();
// 1.缩放
ScaleParameter scaleParam = new ScaleParameter(w, h, Algorithm.LANCZOS); // 缩放参数
if (w < height) {// 如果图片宽和高都小于目标图片则不做缩放处理
scaleParam = new ScaleParameter(w, h, Algorithm.LANCZOS);
} else {
int newWidth = getWidth(w, h, height);
scaleParam = new ScaleParameter(newWidth + 1, height, Algorithm.LANCZOS);
}
PlanarImage planrImage = ImageScaleHelper.scale(imageWrapper.getAsPlanarImage(), scaleParam);
imageWrapper = new ImageWrapper(planrImage);
// 4.输出
outStream = new FileOutputStream(out);
String prefix = out.getName().substring(out.getName().lastIndexOf(".") + 1);
ImageWriteHelper.write(imageWrapper, outStream, outputFormat.getImageFormat(prefix), new WriteParameter());
} catch (IOException e) {
e.printStackTrace();
} catch (SimpleImageException e) {
} finally {
IOUtils.closeQuietly(inStream); // 图片文件输入输出流必须记得关闭
IOUtils.closeQuietly(outStream);
}
}
/**
* 根据宽、高和目标宽度 等比例求高度
*
* @param w
* @param h
* @param width
* @return
*/
public static Integer getHeight(Integer w, Integer h, Integer width) {
return h * width / w;
}
/**
* 根据宽、高和目标高度 等比例求宽度
*
* @param w
* @param h
* @param height
* @return
*/
public static Integer getWidth(Integer w, Integer h, Integer height) {
return w * height / h;
}
/**
* 从中间裁切需要的大小
*
* @param src
* @param target
* @param width
* @param height
*/
@SuppressWarnings("static-access")
public final static void CutCenter(String src, String target, Integer width, Integer height) {
File out = new File(target); // 目的图片
FileOutputStream outStream = null;
File in = new File(src); // 原图片
FileInputStream inStream = null;
try {
inStream = new FileInputStream(in);
ImageWrapper imageWrapper = ImageReadHelper.read(inStream);
int w = imageWrapper.getWidth();
int h = imageWrapper.getHeight();
int x = (w - width) / 2;
int y = (h - height) / 2;
CropParameter cropParam = new CropParameter(x, y, width, height);// 裁切参数
if (x < 0 || y < 0) {
cropParam = new CropParameter(0, 0, w, h);// 裁切参数
}
PlanarImage planrImage = ImageCropHelper.crop(imageWrapper.getAsPlanarImage(), cropParam);
imageWrapper = new ImageWrapper(planrImage);
// 4.输出
outStream = new FileOutputStream(out);
String prefix = out.getName().substring(out.getName().lastIndexOf(".") + 1);
ImageWriteHelper.write(imageWrapper, outStream, outputFormat.getImageFormat(prefix), new WriteParameter());
} catch (IOException e) {
e.printStackTrace();
} catch (SimpleImageException e) {
} finally {
IOUtils.closeQuietly(inStream); // 图片文件输入输出流必须记得关闭
IOUtils.closeQuietly(outStream);
}
}
/**
* 裁切 为正文形
*
* @param src
* @param target
*/
public final static void Cut(String src, String target) {
File out = new File(target); // 目的图片
FileOutputStream outStream = null;
File in = new File(src); // 原图片
FileInputStream inStream = null;
try {
inStream = new FileInputStream(in);
ImageWrapper imageWrapper = ImageReadHelper.read(inStream);
int w = imageWrapper.getWidth();
int h = imageWrapper.getHeight();
int width = 0;
int height = 0;
if (w >= h) {
width = h;
height = h;
} else {
width = w;
height = w;
}
CropParameter cropParam = new CropParameter(0, 0, width, height);// 裁切参数
PlanarImage planrImage = ImageCropHelper.crop(imageWrapper.getAsPlanarImage(), cropParam);
imageWrapper = new ImageWrapper(planrImage);
// 4.输出
outStream = new FileOutputStream(out);
String prefix = out.getName().substring(out.getName().lastIndexOf(".") + 1);
ImageWriteHelper.write(imageWrapper, outStream, outputFormat.getImageFormat(prefix), new WriteParameter());
} catch (IOException e) {
e.printStackTrace();
} catch (SimpleImageException e) {
} finally {
IOUtils.closeQuietly(inStream); // 图片文件输入输出流必须记得关闭
IOUtils.closeQuietly(outStream);
}
}
public static Point calculate(int enclosingWidth, int enclosingHeight,
int width, int height)
{
int x = (enclosingWidth / 2) - (width / 2);
int y = (enclosingHeight / 2) - (height / 2);
return new Point(x, y);
}
//--------------------------------------以下是调整原图竖拍旋转问题 ----------------------------------------
/**
* 上传图片旋转问题
*
* 1.首先获取图片正确显示需要旋转的角度(顺时针)
* @return
*/
public static int getRotateAngleForPhoto(String filePath){
File file = new File(filePath);
int angle = 0;
Metadata metadata;
try {
metadata = JpegMetadataReader.readMetadata(file);
Directory directory = metadata.getDirectory(ExifDirectory.class);
if(directory.containsTag(ExifDirectory.TAG_ORIENTATION)){
// Exif信息中方向
int orientation = directory.getInt(ExifDirectory.TAG_ORIENTATION);
// 原图片的方向信息
if(6 == orientation ){
//6旋转90
angle = 90;
}else if( 3 == orientation){
//3旋转180
angle = 180;
}else if( 8 == orientation){
//8旋转90
angle = 270;
}
}
} catch (JpegProcessingException e) {
e.printStackTrace();
} catch (MetadataException e) {
e.printStackTrace();
}
return angle;
}
/**
* 2.调用 旋转的手机照片
* @param fullPath //原图路径
* @param angel //传入1.
* @return
*/
public static String rotatePhonePhoto(String filePath, int angel){
if(angel == 0){
return filePath;
}
BufferedImage src;
try {
src = ImageIO.read(new File(filePath));
int src_width = src.getWidth(null);
int src_height = src.getHeight(null);
Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension(src_width, src_height)), angel);
BufferedImage res = new BufferedImage(rect_des.width, rect_des.height,BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = res.createGraphics();
g2.translate((rect_des.width - src_width) / 2,
(rect_des.height - src_height) / 2);
g2.rotate(Math.toRadians(angel), src_width / 2, src_height / 2);
g2.drawImage(src, null, null);
ImageIO.write(res, "jpg", new File(filePath));
} catch (IOException e) {
e.printStackTrace();
}
return filePath;
}
public static Rectangle CalcRotatedSize(Rectangle src, int angel) {
// if angel is greater than 90 degree, we need to do some conversion
if (angel >= 90) {
if(angel / 90 % 2 == 1){
int temp = src.height;
src.height = src.width;
src.width = temp;
}
angel = angel % 90;
}
double r = Math.sqrt(src.height * src.height + src.width * src.width) / 2;
double len = 2 * Math.sin(Math.toRadians(angel) / 2) * r;
double angel_alpha = (Math.PI - Math.toRadians(angel)) / 2;
double angel_dalta_width = Math.atan((double) src.height / src.width);
double angel_dalta_height = Math.atan((double) src.width / src.height);
int len_dalta_width = (int) (len * Math.cos(Math.PI - angel_alpha
- angel_dalta_width));
int len_dalta_height = (int) (len * Math.cos(Math.PI - angel_alpha
- angel_dalta_height));
int des_width = src.width + len_dalta_width * 2;
int des_height = src.height + len_dalta_height * 2;
return new java.awt.Rectangle(new Dimension(des_width, des_height));
}
}
Java之~ 上传 图片压缩,阿里图片压缩,图片旋转方法工具类相关推荐
- java百度上传控件_百度Bos上传文件工具类-BosUtils(java)
功能要求 java项目中所有的图片均使用对象存储BOS 准备材料 首先你要又百度bos的账号,找到自己的ak.sk.endpoint.bucketname(这些东西不懂得可以去看bos的文档) 功能代 ...
- java多文件上传plupload控件实现多图片上传(二)
接上篇 java多文件上传plupload控件实现多图片上传(一) 续写PluploadUtil 和 Plupload PO类,以及后台的action. 至此,可实现多文件上传功能. 上传文件Acti ...
- 前端图片压缩上传(纯js的质量压缩,非长宽压缩)
前端图片压缩上传(纯js的质量压缩,非长宽压缩) 此demo为大于1M对图片进行压缩上传 若小于1M则原图上传,可以根据自己实际需求更改. demo源码如下: <!DOCTYPE html> ...
- JAVA如何实现将用户上传的PDF文件转换成图片并返回给用户
很多曾经攻克过的难题都没有及时记录并分享,觉得有些可惜.趁着现在还单身,头还没秃,精力也还算旺盛,我便整理出一些自己曾经挑灯夜战.独立实现的还算有些成就感的项目需求,记录在个人博客上,希望能给拥有相同 ...
- java上传文件至阿里云oss工具类
第一步:引入oss maven坐标 <dependency><groupId>com.aliyun.oss</groupId><artifactId>a ...
- 文件上传、下载、导出(图片上传、下载)
一.文件上传 1.常规文件上传 input 标签 type="file", 点击接收上传的文件 <label for="file_url">< ...
- java 后端 使用 Graphics2D 制作海报,画echarts图,带工具类,各种细节:如头像切割成圆形,文字换行算法(完美实验success),解决画上文字、图片后不清晰问题
文章目录 先看成品 前言 一.项目目录结构 一.海报制作PosterUtil.java工具类 1. 描述 2. 代码 二.测试生成海报 1. 描述 2. 直接上代码 四.其他测试 1. Test1_C ...
- html显示数据库图片django,django将图片上传数据库后在前端显式的方法
1.使用ImageField先安装pillow模块 pip install pillow 2.在app的models中设置 class Image(models.Model): pic_name=mo ...
- php flash 图片上传,php+jquery+ajax无刷新图片上传裁切,模拟flash头像上传实例
这几天自己在写一个cms.之前在用到图片上传裁切的时候总是用的flash的,或者是swfupload之类的.用的还不熟练,所以今天就用ajax做一个图片上传裁切的实例.个人感觉还不错,现在就分享出来. ...
最新文章
- solr kerberos java_solr添加kerberos认证及授权
- python 科学计算基础教程电子版-自学Python 编程基础、科学计算及数据分析
- C#单例模式的懒汉与饿汉
- FFmpeg音频编解码处理
- 如何在 Web 开发中找到第一份工作?
- JQuery的click、bind、delegate、off、unbind
- request 和 session 获取方法
- winsock类型病毒后遗症处理
- HTML5视频放完自动跳转,炫酷html5 网站视频自动跳转代码,零基础秒学
- BM3D图像去噪算法原理及代码详解
- 数据创造价值,数据分析主要为哪几步?
- 关于ARM芯片中的大小端模式
- 初次注册知乎账号,不小心遭受系统限制,该如何解封?
- 读书笔记之——个人知识管理
- 为了防老板偷窥,程序员开源了这个神器
- 【预测模型】基于Logistic混沌映射改进麻雀算法改进BP神经网络实现数据预测matlab源码
- PHP表单TOKEN防止重复提交
- 使用MATLAB快速计算Khatri-Rao积
- 基于matlab的吉他调音器APP(提供附件下载)
- 国外博士后申请需要准备哪些材料?
热门文章
- 基于阿里云官网文档-大数据开发治理平台 DataWorks研读+数据质量扩展+相应的大数据组件知识扩展
- (五)安装axios与最终效果——vue-cli3实例:电商分类网页
- python怎样把if语句写成一行_1.1 if语句
- win10下载安装phpStudy+phpMyAdmin
- 稀有 | GXF Stat 一次统计物种的Gene/mRNA/Exon/Intron/CDS/UTR...信息
- 线代:已知一个特征向量快速求另外两个与之正交的特征向量
- 使用NATS消息中间件实现云边协同
- Loss数据可视化(将txt文件转化为tensorboard)
- 计算机专业课的核心素养是什么,【素养课】计算机就业专业部职业素养课方案成功敲定,阶段核心素养课在一、二年级班顺利展开...
- 鸿蒙操作系统系列——科普篇