Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ A Java interface to [llibvips](http://libvips.github.io/libvips/), the fast imag
<dependency>
<groupId>io.github.codecitizen</groupId>
<artifactId>jlibvips</artifactId>
<version>1.2.1</version>
<version>1.3.0.RELEASE</version>
</dependency>
```

```groovy
implementation 'io.github.codecitizen:jlibvips:1.2.1'
implementation 'io.github.codecitizen:jlibvips:1.3.0.RELEASE'
```

**Configure Path to libvips Library:**

From code:
```java
VipsBindingsSingleton.configure("/usr/local/lib/libvips.so");
```

You may also set the lib path in environment variable `JLIBVIPS_LIB_PATH`, which is useful
when running your app in multiple environments where lib position changes. Example for macOS:
```shell script
export JLIBVIPS_LIB_PATH="/usr/local/Cellar/vips/8.10.2_4/lib/libvips.dylib"
```

**Example: Generate a Thumbnail for a PDF.**

```java
Expand Down Expand Up @@ -52,7 +59,7 @@ public class PDFThumbnailExample {
}
```

**Example: Create an Image Pyramid form a large PNG File.**
**Example: Create a DZ Image Pyramid from a large PNG File.**


```java
Expand All @@ -64,15 +71,44 @@ import java.nio.file.Paths;
public class ImagePyramidExample {

public static void main(String[] args) {
var image = VipsImage.formFile(Paths.get(args[0]));
var image = VipsImage.fromFile(Paths.get(args[0]));
var directory = Files.createTempDirectory("example-pyramid");
image.deepZoom(directory)
.layout(DeepZoomLayouts.Google)
.container(DeepZoomContainer.FileSystem)
.suffix(".jpg[Q=100]")
.save();
image.unref();
System.out.printf("Pyramid generated in folder '%s'.%n", directory.toString());
System.out.printf("Pyramid generated in folder '%s'.\n", directory.toString());
System.out.println("Done.");
}

}
```

**Example: Create a TIFF Image Pyramid from a large PNG File.**

```java
package jlibvips.example;

import org.jlibvips.VipsImage;
import java.nio.file.Paths;

public class ImagePyramidExample {

public static void main(String[] args) {
var image = VipsImage.fromFile(Paths.get(args[0]));
Path dest = image
.tiff()
.tile(true)
.tileHeight(256)
.tileWidth(256)
.compression(VipsForeignTiffCompression.VIPS_FOREIGN_TIFF_COMPRESSION_JPEG)
.quality(80)
.pyramid(true)
.save();
image.unref();
System.out.printf("Pyramid generated in file '%s'.\n", dest.toString());
System.out.println("Done.");
}

Expand Down Expand Up @@ -134,3 +170,5 @@ VIPS[G_LOG_LEVEL_INFO]: gaussblur mask width 17
VIPS[G_LOG_LEVEL_INFO]: convi: using C path
VIPS[G_LOG_LEVEL_INFO]: convi: using C path
```

The GLIBC lib path can also be set using env variable `JLIBVIPS_GLIBC_PATH`.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

group 'io.github.codecitizen'
archivesBaseName = 'jlibvips'
version '1.3.0.RELEASE'
version '1.4.0-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand All @@ -25,10 +25,10 @@ repositories {
}

dependencies {
implementation group: 'net.java.dev.jna', name: 'jna', version: '5.1.0'
implementation 'org.codehaus.groovy:groovy:2.5.4'
implementation group: 'net.java.dev.jna', name: 'jna', version: '5.6.0'
implementation 'org.codehaus.groovy:groovy:2.5.13'

testCompile 'org.spockframework:spock-core:1.2-groovy-2.5'
testCompile 'org.spockframework:spock-core:1.3-groovy-2.5'
}

jar {
Expand Down Expand Up @@ -57,7 +57,7 @@ javadoc {
}

wrapper {
gradleVersion = '5.0'
gradleVersion = '6.7.1'
}

artifacts {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jlibvips/VipsAngle.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static VipsAngle fromInteger(int value) {
case 180: return D180;
case 270: return D270;
default:
throw new IllegalArgumentException("Allowed VipsAngle's are [0°, 90°, 180°, 270°].");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some ASCII encoding error for these characters on my mac, so I removed them

throw new IllegalArgumentException("Allowed VipsAngle's are [0, 90, 180, 270].");
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jlibvips/VipsForeignDzDepth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jlibvips;

/**
* https://libvips.github.io/libvips/API/current/VipsForeignSave.html#VipsForeignDzDepth
*/
public enum VipsForeignDzDepth {
VIPS_FOREIGN_DZ_DEPTH_ONEPIXEL,
VIPS_FOREIGN_DZ_DEPTH_ONETILE,
VIPS_FOREIGN_DZ_DEPTH_ONE,
VIPS_FOREIGN_DZ_DEPTH_LAST
}
13 changes: 13 additions & 0 deletions src/main/java/org/jlibvips/VipsForeignTiffCompression.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jlibvips;

public enum VipsForeignTiffCompression {
VIPS_FOREIGN_TIFF_COMPRESSION_NONE,
VIPS_FOREIGN_TIFF_COMPRESSION_JPEG,
VIPS_FOREIGN_TIFF_COMPRESSION_DEFLATE,
VIPS_FOREIGN_TIFF_COMPRESSION_PACKBITS,
VIPS_FOREIGN_TIFF_COMPRESSION_CCITTFAX4,
VIPS_FOREIGN_TIFF_COMPRESSION_LZW,
VIPS_FOREIGN_TIFF_COMPRESSION_WEBP,
VIPS_FOREIGN_TIFF_COMPRESSION_ZSTD,
VIPS_FOREIGN_TIFF_COMPRESSION_LAST
}
11 changes: 11 additions & 0 deletions src/main/java/org/jlibvips/VipsForeignTiffPredictor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jlibvips;

/**
* https://libvips.github.io/libvips/API/current/VipsForeignSave.html#VipsForeignTiffPredictor
*/
public enum VipsForeignTiffPredictor {
VIPS_FOREIGN_TIFF_PREDICTOR_NONE,
VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL,
VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT,
VIPS_FOREIGN_TIFF_PREDICTOR_LAST
}
10 changes: 10 additions & 0 deletions src/main/java/org/jlibvips/VipsForeignTiffResunit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.jlibvips;

/**
* https://libvips.github.io/libvips/API/current/VipsForeignSave.html#VipsForeignTiffResunit
*/
public enum VipsForeignTiffResunit {
VIPS_FOREIGN_TIFF_RESUNIT_CM,
VIPS_FOREIGN_TIFF_RESUNIT_INCH,
VIPS_FOREIGN_TIFF_RESUNIT_LAST
}
15 changes: 15 additions & 0 deletions src/main/java/org/jlibvips/VipsImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,21 @@ public PngSaveOperation png() {
return new PngSaveOperation(this);
}

/**
* Write an image to a file in TIFF format.
*
* <code>
* java.nio.Path path = image.tiff().save();
* </code>
*
* <a href="http://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-tiffsave">vips_tiffsave()</a>
*
* @return the {@link TiffSaveOperation}
*/
public TiffSaveOperation tiff() {
return new TiffSaveOperation(this);
}

/**
* Get the width of this image.
*
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/jlibvips/VipsRegionShrink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jlibvips;

/**
* https://libvips.github.io/libvips/API/current/VipsRegion.html#VipsRegionShrink
*/
public enum VipsRegionShrink {
VIPS_REGION_SHRINK_MEAN,
VIPS_REGION_SHRINK_MEDIAN,
VIPS_REGION_SHRINK_MODE,
VIPS_REGION_SHRINK_MAX,
VIPS_REGION_SHRINK_MIN,
VIPS_REGION_SHRINK_NEAREST,
VIPS_REGION_SHRINK_LAST
}
1 change: 1 addition & 0 deletions src/main/java/org/jlibvips/jna/VipsBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface VipsBindings extends Library {
int vips_jpegsave(Pointer in, String filename, Object...args);
int vips_webpsave(Pointer in, String filename, Object...args);
int vips_pngsave(Pointer in, String filename, Object...args);
int vips_tiffsave(Pointer in, String filename, Object...args);

int vips_insert(Pointer main, Pointer sub, Pointer[] out, int x, int y, Object...args);
int vips_join(Pointer in1, Pointer in2, Pointer[] out, int direction, Object...args);
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/jlibvips/jna/VipsBindingsSingleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class VipsBindingsSingleton {


private static String libraryPath = "vips";
private static final String ENV_LIB_PATH = "JLIBVIPS_LIB_PATH";
private static String libraryPath = System.getenv(ENV_LIB_PATH) == null ? "vips" : System.getenv(ENV_LIB_PATH);

public static void configure(String lp) {
libraryPath = lp;
Expand All @@ -16,9 +16,13 @@ public static void configure(String lp) {
public static VipsBindings instance() {
if(INSTANCE == null) {
if(libraryPath == null || libraryPath.isEmpty()) {
throw new IllegalStateException("Please call VipsBindingsSingleton.configure(...) before getting the instance.");
throw new IllegalStateException("Please call VipsBindingsSingleton.configure(...) or set env var JLIBVIPS_LIB_PATH before getting the instance.");
}
try {
INSTANCE = Native.load(libraryPath, VipsBindings.class);
} catch (UnsatisfiedLinkError e) {
throw new IllegalStateException("Please call VipsBindingsSingleton.configure(...) or set env var JLIBVIPS_LIB_PATH before getting the instance.");
}
INSTANCE = Native.load(libraryPath, VipsBindings.class);
}
return INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

public class GLibBindingsSingleton {

private static String libraryPath = "/usr/local/opt/glib/lib/libglib-2.0.dylib";
private static final String ENV_GLIBC_PATH = "JLIBVIPS_GLIBC_PATH";
private static String libraryPath = System.getenv(ENV_GLIBC_PATH) == null
? "libglib-2.0"
: System.getenv(ENV_GLIBC_PATH);

public static void configure(String lp) {
libraryPath = lp;
Expand Down
Loading