Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
4b56cfd9d8
|
|||
82e1d3844c
|
|||
4c581052ab
|
|||
705e7f7e7d
|
|||
b00a67c5d0 | |||
e415ead1ec | |||
b8bfa77cc2 | |||
0df492ff14 | |||
4ea2dc7110 | |||
a4bd4b0b96 | |||
dab69b174f | |||
aa61113357 | |||
e43b688d7f | |||
6bd2bbc572 | |||
6d29af7f72 | |||
f81a1c2fbd | |||
847a81534b | |||
8e3a599294 | |||
565832b018 | |||
d6c0c9fd30 |
9
.vscode/extensions.json
vendored
Normal file
9
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
|
"mosapride.zenkaku",
|
||||||
|
"redhat.fabric8-analytics",
|
||||||
|
"streetsidesoftware.code-spell-checker",
|
||||||
|
"vscjava.vscode-java-pack"
|
||||||
|
]
|
||||||
|
}
|
18
.vscode/settings.json
vendored
Normal file
18
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.organizeImports": true
|
||||||
|
},
|
||||||
|
"[jsonc]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
|
},
|
||||||
|
// Extensions - Code Spell Checker
|
||||||
|
"cSpell.ignoreWords": ["endianness", "noflat", "nopix", "omexml"],
|
||||||
|
"cSpell.words": ["bioformats", "imageinfo", "neurodata", "riken"],
|
||||||
|
// Extentions - Prettier
|
||||||
|
"prettier.printWidth": 120,
|
||||||
|
"prettier.singleQuote": true,
|
||||||
|
"prettier.tabWidth": 4,
|
||||||
|
"java.configuration.updateBuildConfiguration": "interactive",
|
||||||
|
"java.compile.nullAnalysis.mode": "automatic"
|
||||||
|
}
|
21
README.md
21
README.md
@ -1,39 +1,48 @@
|
|||||||
# BioFormatsImageInfo
|
# BioFormatsImageInfo
|
||||||
|
|
||||||
Metadata extraction tool based on Bio-Formats
|
Metadata extraction tool based on Bio-Formats
|
||||||
|
|
||||||
### make package
|
## make package
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
mvn package
|
mvn package
|
||||||
```
|
```
|
||||||
|
|
||||||
### run
|
## run
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
./target/dist/bin/bioformats-imageinfo "[path to image file]"
|
./target/dist/bin/bioformats-imageinfo "[path to image file]"
|
||||||
```
|
```
|
||||||
|
|
||||||
### run by jar
|
### run by jar
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
java -jar ./target/dist/lib/bioformats-imageinfo-1.0.0.jar "[path to image file]"
|
java -jar ./target/dist/lib/bioformats-imageinfo-1.2.1.jar "[path to image file]"
|
||||||
```
|
```
|
||||||
|
|
||||||
### run by fat jar
|
### run by fat jar
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
java -jar ./target/bioformats-imageinfo-1.0.0-jar-with-dependencies.jar "[path to image file]"
|
java -jar ./target/bioformats-imageinfo-1.2.1-jar-with-dependencies.jar "[path to image file]"
|
||||||
```
|
```
|
||||||
|
|
||||||
### library usage
|
## library usage
|
||||||
|
|
||||||
```java
|
```java
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import jp.riken.neurodata.tools.BioFormatsImageInfo;
|
import jp.riken.neurodata.tools.BioFormatsImageInfo;
|
||||||
import jp.riken.neurodata.tools.BioFormatsException;
|
import jp.riken.neurodata.tools.BioFormatsImageException;
|
||||||
|
import jp.riken.neurodata.tools.BioFormatsImageThumbnail;
|
||||||
|
|
||||||
String path = "[path to image file]";
|
String path = "[path to image file]";
|
||||||
String format = "";
|
String format = "";
|
||||||
Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
||||||
|
Map<String, Object> thumbnail = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
format = BioFormatsImageInfo.readMetadata(path, metadata);
|
format = BioFormatsImageInfo.readMetadata(path, metadata);
|
||||||
|
BioFormatsImageThumbnail.readThumbnail(path, thumbnail);
|
||||||
} catch (BioFormatsImageException e) {
|
} catch (BioFormatsImageException e) {
|
||||||
// error occurred
|
// error occurred
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
99
pom.xml
99
pom.xml
@ -1,17 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>jp.riken.neurodata.tools.BioFormatsImageInfo</groupId>
|
<groupId>jp.riken.neurodata.tools.BioFormatsImageInfo</groupId>
|
||||||
<artifactId>bioformats-imageinfo</artifactId>
|
<artifactId>bioformats-imageinfo</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.2.1</version>
|
||||||
|
|
||||||
<name>bioformats-imageinfo</name>
|
<name>bioformats-imageinfo</name>
|
||||||
<url>https://neurodata.riken.jp</url>
|
<url>https://neurodata.riken.jp</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<bio-formats.version>6.10.0</bio-formats.version>
|
<bio-formats.version>7.0.1</bio-formats.version>
|
||||||
<bioformats-imageinfo.mainClass>jp.riken.neurodata.tools.BioFormatsImageInfo</bioformats-imageinfo.mainClass>
|
<bioformats-imageinfo.mainClass>jp.riken.neurodata.tools.BioFormatsImageInfo</bioformats-imageinfo.mainClass>
|
||||||
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
@ -27,14 +27,39 @@
|
|||||||
<artifactId>bio-formats-tools</artifactId>
|
<artifactId>bio-formats-tools</artifactId>
|
||||||
<version>${bio-formats.version}</version>
|
<version>${bio-formats.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-nop</artifactId>
|
||||||
|
<version>1.7.30</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>enforce-maven</id>
|
||||||
|
<goals>
|
||||||
|
<goal>enforce</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<requireMavenVersion>
|
||||||
|
<version>3.2.5</version>
|
||||||
|
</requireMavenVersion>
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.6.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>copy-dependencies</id>
|
<id>copy-dependencies</id>
|
||||||
@ -51,7 +76,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
@ -61,34 +86,10 @@
|
|||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<version>3.4.1</version>
|
|
||||||
<configuration>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>${bioformats-imageinfo.mainClass}</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>make-assembly</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>appassembler-maven-plugin</artifactId>
|
<artifactId>appassembler-maven-plugin</artifactId>
|
||||||
<version>1.10</version>
|
<version>2.1.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<assembleDirectory>${project.build.directory}/dist</assembleDirectory>
|
<assembleDirectory>${project.build.directory}/dist</assembleDirectory>
|
||||||
<repositoryLayout>flat</repositoryLayout>
|
<repositoryLayout>flat</repositoryLayout>
|
||||||
@ -109,10 +110,37 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.6.0</version>
|
||||||
|
<configuration>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>${bioformats-imageinfo.mainClass}</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.owasp</groupId>
|
<groupId>org.owasp</groupId>
|
||||||
<artifactId>dependency-check-maven</artifactId>
|
<artifactId>dependency-check-maven</artifactId>
|
||||||
<version>7.1.1</version>
|
<version>8.4.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -128,15 +156,18 @@
|
|||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<id>central</id>
|
<id>central</id>
|
||||||
<name>Central Repository</name>
|
<name>Central Repository</name>
|
||||||
<url>https://repo.maven.apache.org/maven2</url>
|
<!-- <url>https://repo.maven.apache.org/maven2</url> -->
|
||||||
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
<layout>default</layout>
|
<layout>default</layout>
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>central</id>
|
||||||
<name>Central Repository</name>
|
<name>Central Repository</name>
|
||||||
<url>https://repo.maven.apache.org/maven2</url>
|
<!-- <url>https://repo.maven.apache.org/maven2</url> -->
|
||||||
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>ome</id>
|
<id>ome</id>
|
||||||
|
36
src/main/assembly/assembly.xml
Normal file
36
src/main/assembly/assembly.xml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||||
|
<id>bin</id>
|
||||||
|
<formats>
|
||||||
|
<format>tar.gz</format>
|
||||||
|
<format>tar.bz2</format>
|
||||||
|
<format>zip</format>
|
||||||
|
</formats>
|
||||||
|
<fileSets>
|
||||||
|
<fileSet>
|
||||||
|
<directory>target/dist/bin</directory>
|
||||||
|
<outputDirectory>bin</outputDirectory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>*.bat</exclude>
|
||||||
|
</excludes>
|
||||||
|
<directoryMode>0755</directoryMode>
|
||||||
|
<fileMode>0755</fileMode>
|
||||||
|
</fileSet>
|
||||||
|
<fileSet>
|
||||||
|
<directory>target/dist/bin</directory>
|
||||||
|
<outputDirectory>bin</outputDirectory>
|
||||||
|
<includes>
|
||||||
|
<include>*.bat</include>
|
||||||
|
</includes>
|
||||||
|
<directoryMode>0755</directoryMode>
|
||||||
|
<fileMode>0644</fileMode>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
<dependencySets>
|
||||||
|
<dependencySet>
|
||||||
|
<outputDirectory>lib</outputDirectory>
|
||||||
|
</dependencySet>
|
||||||
|
</dependencySets>
|
||||||
|
</assembly>
|
@ -24,29 +24,29 @@ import loci.formats.tools.ImageInfo;
|
|||||||
|
|
||||||
public class BioFormatsImageInfo {
|
public class BioFormatsImageInfo {
|
||||||
|
|
||||||
protected static Map<String, Object> readImages(IFormatReader reader) throws FormatException, IOException {
|
protected static Map<String, Object> readImages(final IFormatReader reader) throws FormatException, IOException {
|
||||||
Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
// read basic metadata
|
// read basic metadata
|
||||||
int seriesCount = reader.getSeriesCount();
|
final int seriesCount = reader.getSeriesCount();
|
||||||
MetadataStore ms = reader.getMetadataStore();
|
final MetadataStore ms = reader.getMetadataStore();
|
||||||
MetadataRetrieve mr = ms instanceof MetadataRetrieve ? (MetadataRetrieve) ms : null;
|
final MetadataRetrieve mr = ms instanceof MetadataRetrieve ? (MetadataRetrieve) ms : null;
|
||||||
for (int j = 0; j < seriesCount; j++) {
|
for (int j = 0; j < seriesCount; j++) {
|
||||||
|
|
||||||
// read basic metadata for series #j
|
// read basic metadata for series #j
|
||||||
reader.setSeries(j);
|
reader.setSeries(j);
|
||||||
Map<String, Object> seriesMetadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> seriesMetadata = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
int imageCount = reader.getImageCount();
|
final int imageCount = reader.getImageCount();
|
||||||
int resolutionCount = reader.getResolutionCount();
|
final int resolutionCount = reader.getResolutionCount();
|
||||||
String seriesName = mr == null ? null : mr.getImageName(j);
|
final String seriesName = mr == null ? null : mr.getImageName(j);
|
||||||
if (seriesName != null) {
|
if (seriesName != null) {
|
||||||
seriesMetadata.put("name", seriesName);
|
seriesMetadata.put("name", seriesName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolutions
|
// resolutions
|
||||||
if (resolutionCount > 1) {
|
if (resolutionCount > 1) {
|
||||||
Map<String, Object> resolutionsMetadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> resolutionsMetadata = new LinkedHashMap<String, Object>();
|
||||||
for (int i = 0; i < resolutionCount; i++) {
|
for (int i = 0; i < resolutionCount; i++) {
|
||||||
reader.setResolution(i);
|
reader.setResolution(i);
|
||||||
resolutionsMetadata.put(String.format("resolution[%d]", i),
|
resolutionsMetadata.put(String.format("resolution[%d]", i),
|
||||||
@ -62,15 +62,16 @@ public class BioFormatsImageInfo {
|
|||||||
|
|
||||||
// indexed
|
// indexed
|
||||||
{
|
{
|
||||||
List<Object> indexed = new ArrayList<Object>();
|
final List<Object> indexed = new ArrayList<Object>();
|
||||||
indexed.add(reader.isIndexed());
|
indexed.add(reader.isIndexed());
|
||||||
indexed.add(String.format("%b color", !reader.isFalseColor()));
|
indexed.add(String.format("%b color", !reader.isFalseColor()));
|
||||||
byte[][] table8 = reader.get8BitLookupTable();
|
final byte[][] table8 = reader.get8BitLookupTable();
|
||||||
if (table8 != null) {
|
if (table8 != null) {
|
||||||
indexed.add(
|
indexed.add(
|
||||||
String.format("8-bit LUT: %d x %s", table8.length, table8[0] == null ? "null" : "" + table8[0].length));
|
String.format("8-bit LUT: %d x %s", table8.length,
|
||||||
|
table8[0] == null ? "null" : "" + table8[0].length));
|
||||||
}
|
}
|
||||||
short[][] table16 = reader.get16BitLookupTable();
|
final short[][] table16 = reader.get16BitLookupTable();
|
||||||
if (table16 != null) {
|
if (table16 != null) {
|
||||||
indexed.add(String.format("16-bit LUT: %d x %s", table16.length,
|
indexed.add(String.format("16-bit LUT: %d x %s", table16.length,
|
||||||
table16[0] == null ? "null" : "" + table16[0].length));
|
table16[0] == null ? "null" : "" + table16[0].length));
|
||||||
@ -80,10 +81,11 @@ public class BioFormatsImageInfo {
|
|||||||
|
|
||||||
seriesMetadata.put("sizeX", reader.getSizeX());
|
seriesMetadata.put("sizeX", reader.getSizeX());
|
||||||
seriesMetadata.put("sizeY", reader.getSizeY());
|
seriesMetadata.put("sizeY", reader.getSizeY());
|
||||||
int sizeZ = reader.getSizeZ();
|
final int sizeZ = reader.getSizeZ();
|
||||||
seriesMetadata.put("sizeZ", makeDimension(sizeZ, sizeZ, reader.getModuloZ()));
|
seriesMetadata.put("sizeZ", makeDimension(sizeZ, sizeZ, reader.getModuloZ()));
|
||||||
seriesMetadata.put("sizeC", makeDimension(reader.getSizeC(), reader.getEffectiveSizeC(), reader.getModuloC()));
|
seriesMetadata.put("sizeC",
|
||||||
int sizeT = reader.getSizeT();
|
makeDimension(reader.getSizeC(), reader.getEffectiveSizeC(), reader.getModuloC()));
|
||||||
|
final int sizeT = reader.getSizeT();
|
||||||
seriesMetadata.put("sizeT", makeDimension(sizeT, sizeT, reader.getModuloT()));
|
seriesMetadata.put("sizeT", makeDimension(sizeT, sizeT, reader.getModuloT()));
|
||||||
seriesMetadata.put("tileSize", makeRectangle(reader.getOptimalTileWidth(), reader.getOptimalTileHeight()));
|
seriesMetadata.put("tileSize", makeRectangle(reader.getOptimalTileWidth(), reader.getOptimalTileHeight()));
|
||||||
seriesMetadata.put("thumbnailSize", makeRectangle(reader.getThumbSizeX(), reader.getThumbSizeY()));
|
seriesMetadata.put("thumbnailSize", makeRectangle(reader.getThumbSizeX(), reader.getThumbSizeY()));
|
||||||
@ -97,7 +99,7 @@ public class BioFormatsImageInfo {
|
|||||||
|
|
||||||
// plane
|
// plane
|
||||||
{
|
{
|
||||||
int[] indices;
|
final int[] indices;
|
||||||
if (imageCount > 6) {
|
if (imageCount > 6) {
|
||||||
int q = imageCount / 2;
|
int q = imageCount / 2;
|
||||||
indices = new int[] { 0, q - 2, q - 1, q, q + 1, q + 2, imageCount - 1 };
|
indices = new int[] { 0, q - 2, q - 1, q, q + 1, q + 2, imageCount - 1 };
|
||||||
@ -108,12 +110,12 @@ public class BioFormatsImageInfo {
|
|||||||
} else {
|
} else {
|
||||||
indices = new int[] { 0 };
|
indices = new int[] { 0 };
|
||||||
}
|
}
|
||||||
int[][] zct = new int[indices.length][];
|
final int[][] zct = new int[indices.length][];
|
||||||
int[] indices2 = new int[indices.length];
|
final int[] indices2 = new int[indices.length];
|
||||||
for (int i = 0; i < indices.length; i++) {
|
for (int i = 0; i < indices.length; i++) {
|
||||||
zct[i] = reader.getZCTCoords(indices[i]);
|
zct[i] = reader.getZCTCoords(indices[i]);
|
||||||
indices2[i] = reader.getIndex(zct[i][0], zct[i][1], zct[i][2]);
|
indices2[i] = reader.getIndex(zct[i][0], zct[i][1], zct[i][2]);
|
||||||
Map<String, Object> planeMetadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> planeMetadata = new LinkedHashMap<String, Object>();
|
||||||
planeMetadata.put("Z", zct[i][0]);
|
planeMetadata.put("Z", zct[i][0]);
|
||||||
planeMetadata.put("C", zct[i][1]);
|
planeMetadata.put("C", zct[i][1]);
|
||||||
planeMetadata.put("T", zct[i][2]);
|
planeMetadata.put("T", zct[i][2]);
|
||||||
@ -129,37 +131,37 @@ public class BioFormatsImageInfo {
|
|||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Map<String, Object> readAnnotations(IFormatReader reader) {
|
protected static Map<String, Object> readAnnotations(final IFormatReader reader) {
|
||||||
Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
||||||
// global metadata
|
// global metadata
|
||||||
Hashtable<String, Object> globalMetadata = reader.getGlobalMetadata();
|
final Hashtable<String, Object> globalMetadata = reader.getGlobalMetadata();
|
||||||
for (String key : MetadataTools.keys(globalMetadata)) {
|
for (String key : MetadataTools.keys(globalMetadata)) {
|
||||||
metadata.put(key, globalMetadata.get(key));
|
metadata.put(key, globalMetadata.get(key));
|
||||||
}
|
}
|
||||||
// original metadata
|
// original metadata
|
||||||
int seriesCount = reader.getSeriesCount();
|
final int seriesCount = reader.getSeriesCount();
|
||||||
for (int j = 0; j < seriesCount; j++) {
|
for (int j = 0; j < seriesCount; j++) {
|
||||||
reader.setSeries(j);
|
reader.setSeries(j);
|
||||||
Hashtable<String, Object> seriesMagedata = reader.getSeriesMetadata();
|
final Hashtable<String, Object> seriesMetadata = reader.getSeriesMetadata();
|
||||||
if (!seriesMagedata.isEmpty()) {
|
if (!seriesMetadata.isEmpty()) {
|
||||||
Map<String, Object> seriesMetadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> originalMetadata = new LinkedHashMap<String, Object>();
|
||||||
String[] keys = MetadataTools.keys(seriesMagedata);
|
final String[] keys = MetadataTools.keys(seriesMetadata);
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
seriesMetadata.put(keys[i], seriesMagedata.get(keys[i]));
|
originalMetadata.put(keys[i], seriesMetadata.get(keys[i]));
|
||||||
}
|
}
|
||||||
metadata.put(String.format("series[%d]", j), seriesMetadata);
|
metadata.put(String.format("series[%d]", j), originalMetadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Object makeDimension(int size, int effSize, Modulo modulo) {
|
protected static Object makeDimension(final int size, final int effSize, final Modulo modulo) {
|
||||||
int mLength = modulo.length();
|
final int mLength = modulo.length();
|
||||||
if (size == effSize && mLength == 1) {
|
if (size == effSize && mLength == 1) {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
List<Object> ret = new ArrayList<Object>();
|
final List<Object> ret = new ArrayList<Object>();
|
||||||
ret.add(size);
|
ret.add(size);
|
||||||
if (size != effSize) {
|
if (size != effSize) {
|
||||||
ret.add(String.format("(effectively %d)", effSize));
|
ret.add(String.format("(effectively %d)", effSize));
|
||||||
@ -171,35 +173,37 @@ public class BioFormatsImageInfo {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Map<String, Object> makeRectangle(int width, int height) {
|
protected static Map<String, Object> makeRectangle(final int width, final int height) {
|
||||||
Map<String, Object> ret = new LinkedHashMap<String, Object>();
|
final Map<String, Object> ret = new LinkedHashMap<String, Object>();
|
||||||
ret.put("width", width);
|
ret.put("width", width);
|
||||||
ret.put("height", height);
|
ret.put("height", height);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String getJsonString(Map<String, Object> map) {
|
protected static String getJsonString(final Map<String, Object> map) {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
String json = null;
|
String json = null;
|
||||||
try {
|
try {
|
||||||
// json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
|
// json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
|
||||||
json = mapper.writeValueAsString(map);
|
json = mapper.writeValueAsString(map);
|
||||||
} catch (Exception e) {
|
} catch (final Throwable e) {
|
||||||
// return "null" if conversion error occured
|
// return "null" if conversion error occurred
|
||||||
json = "null";
|
json = "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String readMetadata(String path, Map<String, Object> metadata) throws BioFormatsImageException {
|
public static String readMetadata(final String path, final Map<String, Object> metadata)
|
||||||
|
throws BioFormatsImageException {
|
||||||
if (FilenameUtils.getExtension(path).toLowerCase().equals("zip")) {
|
if (FilenameUtils.getExtension(path).toLowerCase().equals("zip")) {
|
||||||
// ignore if file is zip archive
|
// ignore if file is zip archive
|
||||||
throw new BioFormatsImageException("Zip is not supported");
|
throw new BioFormatsImageException("Zip is not supported");
|
||||||
}
|
}
|
||||||
String format = "";
|
String format = "";
|
||||||
ImageInfo info = new ImageInfo();
|
final ImageInfo info = new ImageInfo();
|
||||||
IFormatReader reader = new ImageReader();
|
final IFormatReader reader = new ImageReader();
|
||||||
try {
|
try {
|
||||||
// info.parseArgs(new String[] { path, "-nopix", "-noflat", "-omexml" });
|
// info.parseArgs(new String[] { path, "-nopix", "-noflat", "-omexml" });
|
||||||
info.parseArgs(new String[] { path, "-nopix", "-noflat" });
|
info.parseArgs(new String[] { path, "-nopix", "-noflat" });
|
||||||
@ -220,17 +224,17 @@ public class BioFormatsImageInfo {
|
|||||||
reader.setResolution(0);
|
reader.setResolution(0);
|
||||||
// info.printGlobalMetadata();
|
// info.printGlobalMetadata();
|
||||||
// info.printOriginalMetadata();
|
// info.printOriginalMetadata();
|
||||||
Map<String, Object> annotations = readAnnotations(reader);
|
final Map<String, Object> annotations = readAnnotations(reader);
|
||||||
if (!annotations.isEmpty()) {
|
if (!annotations.isEmpty()) {
|
||||||
metadata.put("annotations", annotations);
|
metadata.put("annotations", annotations);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (final Throwable e) {
|
||||||
throw new BioFormatsImageException(e);
|
throw new BioFormatsImageException(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new BioFormatsImageException(e);
|
throw new BioFormatsImageException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,30 +244,35 @@ public class BioFormatsImageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -- Main method --
|
// -- Main method --
|
||||||
public static void main(String[] args) {
|
public static void main(final String[] args) {
|
||||||
boolean status = true;
|
boolean status = true;
|
||||||
String message = "";
|
String message = "";
|
||||||
String format = "";
|
String format = "";
|
||||||
Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
||||||
|
final Map<String, Object> thumbnail = new LinkedHashMap<String, Object>();
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
status = false;
|
status = false;
|
||||||
message = "filename argument required";
|
message = "filename argument required";
|
||||||
} else {
|
} else {
|
||||||
|
final String path = args[0];
|
||||||
try {
|
try {
|
||||||
DebugTools.enableLogging("ERROR");
|
DebugTools.enableLogging("OFF");
|
||||||
format = readMetadata(args[0], metadata);
|
format = readMetadata(path, metadata);
|
||||||
} catch (BioFormatsImageException e) {
|
BioFormatsImageThumbnail.readThumbnail(path, thumbnail);
|
||||||
|
} catch (Throwable t) {
|
||||||
status = false;
|
status = false;
|
||||||
|
message = t.getMessage();
|
||||||
metadata.clear();
|
metadata.clear();
|
||||||
message = e.getMessage();
|
thumbnail.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> results = new LinkedHashMap<String, Object>();
|
final Map<String, Object> results = new LinkedHashMap<String, Object>();
|
||||||
results.put("status", status);
|
results.put("status", status);
|
||||||
results.put("message", message);
|
results.put("message", message);
|
||||||
results.put("format", format);
|
results.put("format", format);
|
||||||
results.put("metadata", metadata.isEmpty() ? null : metadata);
|
results.put("metadata", metadata.isEmpty() ? null : metadata);
|
||||||
|
results.put("thumbnail", thumbnail.isEmpty() ? null : thumbnail);
|
||||||
System.out.println(getJsonString(results));
|
System.out.println(getJsonString(results));
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
|
@ -0,0 +1,274 @@
|
|||||||
|
package jp.riken.neurodata.tools;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.imageio.IIOImage;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.imageio.ImageWriteParam;
|
||||||
|
import javax.imageio.ImageWriter;
|
||||||
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
|
|
||||||
|
import loci.common.DebugTools;
|
||||||
|
import loci.formats.FormatException;
|
||||||
|
import loci.formats.ImageReader;
|
||||||
|
import loci.formats.gui.AWTImageTools;
|
||||||
|
import loci.formats.gui.BufferedImageReader;
|
||||||
|
|
||||||
|
public class BioFormatsImageThumbnail {
|
||||||
|
|
||||||
|
protected static final float JPEG_QUALITY = 0.85f;
|
||||||
|
protected static final int BACKGROUND_COLOR = 0x000000;
|
||||||
|
protected static final double MAXIMUM_SCALE = 2.0;
|
||||||
|
|
||||||
|
public static BufferedImage resize(final BufferedImage image, final int width, final int height) {
|
||||||
|
final boolean hasAlpha = image.getColorModel().hasAlpha();
|
||||||
|
final int imageWidth = image.getWidth();
|
||||||
|
final int imageHeight = image.getHeight();
|
||||||
|
final double scaleWidth = (double) width / (double) imageWidth;
|
||||||
|
final double scaleHeight = (double) height / (double) imageHeight;
|
||||||
|
double scale = Math.min(scaleWidth, scaleHeight);
|
||||||
|
if (scale > MAXIMUM_SCALE) {
|
||||||
|
// limit scaling size to maximum scale
|
||||||
|
scale = MAXIMUM_SCALE;
|
||||||
|
}
|
||||||
|
int resizeWidth = imageWidth;
|
||||||
|
int resizeHeight = imageHeight;
|
||||||
|
Image resizeImage = image;
|
||||||
|
if (scale != 1.0) {
|
||||||
|
// resize image if dimension is different with requested dimension.
|
||||||
|
resizeWidth = (int) (scale * (double) imageWidth);
|
||||||
|
resizeHeight = (int) (scale * (double) imageHeight);
|
||||||
|
resizeImage = image.getScaledInstance(resizeWidth, resizeHeight, Image.SCALE_AREA_AVERAGING);
|
||||||
|
}
|
||||||
|
final int type = hasAlpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
|
||||||
|
final BufferedImage ret = new BufferedImage(width, height, type);
|
||||||
|
final Graphics2D g = ret.createGraphics();
|
||||||
|
final Color c = new Color(image.getRGB(0, 0), hasAlpha);
|
||||||
|
final int offsetX = (width - resizeWidth) / 2;
|
||||||
|
final int offsetY = (height - resizeHeight) / 2;
|
||||||
|
// System.out.println("original:" + imageWidth + "," + imageHeight);
|
||||||
|
// System.out.println("resize:" + resizeWidth + "," + resizeHeight);
|
||||||
|
// System.out.println("target:" + width + "," + height);
|
||||||
|
// System.out.println("offset:" + offsetX + "," + offsetY);
|
||||||
|
g.setColor(c);
|
||||||
|
g.fillRect(0, 0, width, height);
|
||||||
|
g.drawImage(resizeImage, offsetX, offsetY, resizeWidth, resizeHeight, null);
|
||||||
|
g.dispose();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static BufferedImage removeAlphaChannel(final BufferedImage image, final int matColor) {
|
||||||
|
if (!image.getColorModel().hasAlpha()) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
final BufferedImage ret = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
|
final Graphics2D g = ret.createGraphics();
|
||||||
|
g.setColor(new Color(matColor, false));
|
||||||
|
g.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||||
|
g.drawImage(image, 0, 0, null);
|
||||||
|
g.dispose();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static byte[] getJpegByteArray(final BufferedImage image, final float quality, final int matColor)
|
||||||
|
throws BioFormatsImageException {
|
||||||
|
byte[] ret = null;
|
||||||
|
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
final ImageOutputStream ios = ImageIO.createImageOutputStream(bos);) {
|
||||||
|
final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
|
||||||
|
final ImageWriteParam param = writer.getDefaultWriteParam();
|
||||||
|
if (param.canWriteCompressed()) {
|
||||||
|
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
|
param.setCompressionQuality(quality);
|
||||||
|
}
|
||||||
|
writer.setOutput(ios);
|
||||||
|
writer.write(null, new IIOImage(removeAlphaChannel(image, matColor), null, null), param);
|
||||||
|
writer.dispose();
|
||||||
|
ret = bos.toByteArray();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new BioFormatsImageException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static byte[] getPngByteArray(final BufferedImage image) throws BioFormatsImageException {
|
||||||
|
byte[] ret = null;
|
||||||
|
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
final ImageOutputStream ios = ImageIO.createImageOutputStream(bos);) {
|
||||||
|
final ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next();
|
||||||
|
final ImageWriteParam param = writer.getDefaultWriteParam();
|
||||||
|
if (param.canWriteCompressed()) {
|
||||||
|
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
|
param.setCompressionQuality(0.0f);
|
||||||
|
}
|
||||||
|
writer.setOutput(ios);
|
||||||
|
writer.write(null, new IIOImage(image, null, null), param);
|
||||||
|
writer.dispose();
|
||||||
|
ret = bos.toByteArray();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new BioFormatsImageException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDataUri(final BufferedImage image, final String mimeType) throws BioFormatsImageException {
|
||||||
|
byte[] bytes = null;
|
||||||
|
switch (mimeType) {
|
||||||
|
case "image/png":
|
||||||
|
bytes = getPngByteArray(image);
|
||||||
|
break;
|
||||||
|
case "image/jpeg":
|
||||||
|
bytes = getJpegByteArray(image, JPEG_QUALITY, BACKGROUND_COLOR);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new BioFormatsImageException("Unsupported image format: " + mimeType);
|
||||||
|
}
|
||||||
|
if (bytes.length == 0) {
|
||||||
|
throw new BioFormatsImageException("Failed to convert to " + mimeType + " format");
|
||||||
|
}
|
||||||
|
final String dataUri = "data:" + mimeType + ";base64," + Base64.getEncoder().encodeToString(bytes);
|
||||||
|
|
||||||
|
return dataUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedImage getImageFromBioFormatsFile(final String path) throws BioFormatsImageException {
|
||||||
|
BufferedImage ret = null;
|
||||||
|
final BufferedImageReader reader = new BufferedImageReader(new ImageReader());
|
||||||
|
reader.setFlattenedResolutions(false);
|
||||||
|
reader.setNormalized(true);
|
||||||
|
reader.setOriginalMetadataPopulated(false);
|
||||||
|
reader.setMetadataFiltered(true);
|
||||||
|
try {
|
||||||
|
reader.setId(path);
|
||||||
|
} catch (FormatException | IOException e) {
|
||||||
|
throw new BioFormatsImageException("unsupported file: " + path);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw new BioFormatsImageException(t);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
int series = 0;
|
||||||
|
final int seriesCount = reader.getSeriesCount();
|
||||||
|
for (int i = 0; i < seriesCount; i++) {
|
||||||
|
reader.setSeries(i);
|
||||||
|
if (reader.isThumbnailSeries()) {
|
||||||
|
series = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.setSeries(series);
|
||||||
|
final int z = reader.getSizeZ() / 2; // middle of slices
|
||||||
|
final int t = reader.getSizeT() / 2; // middle of frames
|
||||||
|
final int c = 0; // first channel
|
||||||
|
final int no = reader.getIndex(z, c, t);
|
||||||
|
// System.out.println("series count: " + seriesCount);
|
||||||
|
// System.out.println("image count: " + reader.getImageCount());
|
||||||
|
// System.out.println("resolution: " + reader.getResolutionCount());
|
||||||
|
// System.out.println("thumbnail series: " + series);
|
||||||
|
ret = reader.openThumbImage(no);
|
||||||
|
final boolean is16bit = reader.getBitsPerPixel() > 8;
|
||||||
|
final boolean isGrayScale = ret.getSampleModel().getNumBands() == 1;
|
||||||
|
if (is16bit || isGrayScale) {
|
||||||
|
// perform auto scaling if 16bit or gray scale thumbnail image.
|
||||||
|
ret = AWTImageTools.autoscale(ret);
|
||||||
|
}
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
for (Throwable e = t; e != null; e = e.getCause()) {
|
||||||
|
if (e instanceof OutOfMemoryError) {
|
||||||
|
throw new BioFormatsImageException("out of memory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new BioFormatsImageException(t);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new BioFormatsImageException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedImage getImageFromFile(final String path) throws BioFormatsImageException {
|
||||||
|
BufferedImage ret = null;
|
||||||
|
final File file = new File(path);
|
||||||
|
try {
|
||||||
|
ret = ImageIO.read(file);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new BioFormatsImageException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveFile(final String dataUri, final String path) throws BioFormatsImageException {
|
||||||
|
final Pattern pattern = Pattern.compile("^data:(image/[^;]+);(base64|utf8),(.*)$", Pattern.MULTILINE);
|
||||||
|
final Matcher matcher = pattern.matcher(dataUri);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
throw new BioFormatsImageException("Unsupported data URI format");
|
||||||
|
}
|
||||||
|
final byte[] bytes = matcher.group(2) == "utf8" ? matcher.group(3).getBytes()
|
||||||
|
: Base64.getDecoder().decode(matcher.group(3));
|
||||||
|
try (final FileOutputStream fos = new FileOutputStream(path);) {
|
||||||
|
fos.write(bytes);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new BioFormatsImageException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean readThumbnail(final String path, final Map<String, Object> thumbnail) {
|
||||||
|
boolean ret = true;
|
||||||
|
try {
|
||||||
|
final BufferedImage image = getImageFromBioFormatsFile(path);
|
||||||
|
final int width = image.getWidth();
|
||||||
|
final int height = image.getHeight();
|
||||||
|
final String mimeType = image.getColorModel().hasAlpha() ? "image/png" : "image/jpeg";
|
||||||
|
final String dataUri = getDataUri(image, mimeType);
|
||||||
|
thumbnail.put("width", width);
|
||||||
|
thumbnail.put("height", height);
|
||||||
|
thumbnail.put("mimeType", mimeType);
|
||||||
|
thumbnail.put("url", dataUri);
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
// ignore
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
if (args.length != 1) {
|
||||||
|
System.out.println("filename argument required");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
final String path = args[0];
|
||||||
|
try {
|
||||||
|
DebugTools.enableLogging("OFF");
|
||||||
|
BufferedImage image = getImageFromBioFormatsFile(path);
|
||||||
|
final String format = image.getColorModel().hasAlpha() ? "png" : "jpeg";
|
||||||
|
// image = resize(image, 160, 160);
|
||||||
|
final String dataUri = getDataUri(image, "image/" + format);
|
||||||
|
System.out.println(dataUri);
|
||||||
|
// saveFile(dataUri, "/var/tmp/thumbnail." + format);
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
// t.printStackTrace();
|
||||||
|
System.out.println(t.getMessage());
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user