initial commit
This commit is contained in:
parent
cdbdf611d2
commit
b1f1f275cf
|
@ -1,73 +1,98 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>image-processing</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>image-processing</name>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>image-processing</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>image-processing</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.imagej</groupId>
|
||||
<artifactId>ij</artifactId>
|
||||
<version>${ij.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openimaj</groupId>
|
||||
<artifactId>core-image</artifactId>
|
||||
<version>${core-image.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openpnp</groupId>
|
||||
<artifactId>opencv</artifactId>
|
||||
<version>3.4.2-0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-core</artifactId>
|
||||
<version>${imageio.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-bmp</artifactId>
|
||||
<version>${imageio.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.tess4j</groupId>
|
||||
<artifactId>tess4j</artifactId>
|
||||
<version>${tess4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>tesseract-platform</artifactId>
|
||||
<version>${tesseract-platform.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<core-image.version>1.3.5</core-image.version>
|
||||
<ij.version>1.51h</ij.version>
|
||||
<imageio.version>3.3.2</imageio.version>
|
||||
<tess4j.version>4.5.1</tess4j.version>
|
||||
<tesseract-platform.version>4.1.0-1.5.2</tesseract-platform.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.imagej</groupId>
|
||||
<artifactId>ij</artifactId>
|
||||
<version>${ij.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openimaj</groupId>
|
||||
<artifactId>core-image</artifactId>
|
||||
<version>${core-image.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openpnp</groupId>
|
||||
<artifactId>opencv</artifactId>
|
||||
<version>3.4.2-0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-core</artifactId>
|
||||
<version>${imageio.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-bmp</artifactId>
|
||||
<version>${imageio.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.tess4j</groupId>
|
||||
<artifactId>tess4j</artifactId>
|
||||
<version>${tess4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>tesseract-platform</artifactId>
|
||||
<version>${tesseract-platform.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.imgscalr</groupId>
|
||||
<artifactId>imgscalr-lib</artifactId>
|
||||
<version>${imgscalr-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>${thumbnailator-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.downgoon</groupId>
|
||||
<artifactId>marvin</artifactId>
|
||||
<version>${marvin-version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.downgoon</groupId>
|
||||
<artifactId>MarvinPlugins</artifactId>
|
||||
<version>${marvin-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<core-image.version>1.3.5</core-image.version>
|
||||
<ij.version>1.51h</ij.version>
|
||||
<imageio.version>3.3.2</imageio.version>
|
||||
<tess4j.version>4.5.1</tess4j.version>
|
||||
<tesseract-platform.version>4.1.0-1.5.2</tesseract-platform.version>
|
||||
<imgscalr-version>4.2</imgscalr-version>
|
||||
<thumbnailator-version>0.4.11</thumbnailator-version>
|
||||
<marvin-version>1.5.5</marvin-version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,25 @@
|
|||
package com.baeldung.image.resize.core;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class Graphics2DExample {
|
||||
|
||||
static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException {
|
||||
BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics2D = resizedImage.createGraphics();
|
||||
graphics2D.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null);
|
||||
graphics2D.dispose();
|
||||
return resizedImage;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg"));
|
||||
BufferedImage outputImage = resizeImage(originalImage, 200, 200);
|
||||
ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.image.resize.core;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ImageScaledInstanceExample {
|
||||
static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException {
|
||||
Image resultingImage = originalImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_DEFAULT);
|
||||
BufferedImage bufferedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
|
||||
bufferedImage.getGraphics()
|
||||
.drawImage(resultingImage, 0, 0, null);
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg"));
|
||||
BufferedImage outputImage = resizeImage(originalImage, 200, 200);
|
||||
ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.image.resize.imagescalr;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.imgscalr.Scalr;
|
||||
|
||||
public class ImagescalrExample {
|
||||
static BufferedImage simpleResizeImage(BufferedImage originalImage, int targetWidth) throws Exception {
|
||||
return Scalr.resize(originalImage, targetWidth);
|
||||
}
|
||||
|
||||
static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception {
|
||||
return Scalr.resize(originalImage, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, targetWidth, targetHeight, Scalr.OP_ANTIALIAS);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg"));
|
||||
BufferedImage outputImage = resizeImage(originalImage, 200, 200);
|
||||
ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.baeldung.image.resize.marvin;
|
||||
|
||||
import org.marvinproject.image.transform.scale.Scale;
|
||||
|
||||
import marvin.image.MarvinImage;
|
||||
import marvin.io.MarvinImageIO;
|
||||
|
||||
public class MarvinExample {
|
||||
static void resizeImage(String originalImagePath, int targetWidth, int targetHeight, String outputImagePath) {
|
||||
MarvinImage image = MarvinImageIO.loadImage(originalImagePath);
|
||||
Scale scale = new Scale();
|
||||
scale.load();
|
||||
scale.setAttribute("newWidth", targetWidth);
|
||||
scale.setAttribute("newHeight", targetHeight);
|
||||
scale.process(image.clone(), image, null, null, false);
|
||||
MarvinImageIO.saveImage(image, outputImagePath);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
resizeImage("src/main/resources/images/sampleImage.jpg", 200, 200, "src/main/resources/images/sampleImage1.jpg");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.baeldung.image.resize.thumbnailator;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
|
||||
public class ThumbnailatorExample {
|
||||
static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
Thumbnails.of(originalImage)
|
||||
.size(targetWidth, targetHeight)
|
||||
.outputFormat("JPEG")
|
||||
.outputQuality(0.90)
|
||||
.toOutputStream(outputStream);
|
||||
byte[] data = outputStream.toByteArray();
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
|
||||
return ImageIO.read(inputStream);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg"));
|
||||
BufferedImage outputImage = resizeImage(originalImage, 200, 200);
|
||||
ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue