Go package for fast high-level image processing powered by libvips C library

Overview

bimg Build Status GoDoc Go Report Card Coverage Status License

Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API.

bimg was designed to be a small and efficient library supporting common image operations such as crop, resize, rotate, zoom or watermark. It can read JPEG, PNG, WEBP natively, and optionally TIFF, PDF, GIF and SVG formats if [email protected]+ is compiled with proper library bindings. Lastly AVIF is supported as of [email protected]+. For AVIF support libheif needs to be compiled with an applicable AVIF en-/decoder.

bimg is able to output images as JPEG, PNG and WEBP formats, including transparent conversion across them.

bimg uses internally libvips, a powerful library written in C for image processing which requires a low memory footprint and it's typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings or Go native image package, and in some cases it's even 8x faster processing JPEG images.

If you're looking for an HTTP based image processing solution, see imaginary.

bimg was heavily inspired in sharp, its homologous package built for node.js. bimg is used in production environments processing thousands of images per day.

v1 notice: bimg introduces some minor breaking changes in v1 release. If you're using gopkg.in, you can still rely in the v0 without worrying about API breaking changes.

Contents

Supported image operations

  • Resize
  • Enlarge
  • Crop (including smart crop support, libvips 8.5+)
  • Rotate (with auto-rotate based on EXIF orientation)
  • Flip (with auto-flip based on EXIF metadata)
  • Flop
  • Zoom
  • Thumbnail
  • Extract area
  • Watermark (using text or image)
  • Gaussian blur effect
  • Custom output color space (RGB, grayscale...)
  • Format conversion (with additional quality/compression settings)
  • EXIF metadata (size, alpha channel, profile, orientation...)
  • Trim (libvips 8.6+)

Prerequisites

  • libvips 8.3+ (8.8+ recommended)
  • C compatible compiler such as gcc 4.6+ or clang 3.0+
  • Go 1.3+

Note:

  • libvips v8.3+ is required for GIF, PDF and SVG support.
  • libvips v8.9+ is required for AVIF support. libheif compiled with a AVIF en-/decoder also needs to be present.

Installation

go get -u github.com/h2non/bimg

libvips

Follow libvips installation instructions:

https://libvips.github.io/libvips/install.html

Installation script

Note: install script is officially deprecated, it might not work as expected. We recommend following libvips install instructions.

Run the following script as sudo (supports OSX, Debian/Ubuntu, Redhat, Fedora, Amazon Linux):

curl -s https://raw.githubusercontent.com/h2non/bimg/master/preinstall.sh | sudo bash -

If you want to take the advantage of OpenSlide, simply add --with-openslide to enable it:

curl -s https://raw.githubusercontent.com/h2non/bimg/master/preinstall.sh | sudo bash -s --with-openslide

The install script requires curl and pkg-config.

Performance

libvips is probably the fastest open source solution for image processing. Here you can see some performance test comparisons for multiple scenarios:

Benchmark

Tested using Go 1.5.1 and libvips-7.42.3 in OSX i7 2.7Ghz

BenchmarkRotateJpeg-8     	      20	  64686945 ns/op
BenchmarkResizeLargeJpeg-8	      20	  63390416 ns/op
BenchmarkResizePng-8      	     100	  18147294 ns/op
BenchmarkResizeWebP-8     	     100	  20836741 ns/op
BenchmarkConvertToJpeg-8  	     100	  12831812 ns/op
BenchmarkConvertToPng-8   	      10	 128901422 ns/op
BenchmarkConvertToWebp-8  	      10	 204027990 ns/op
BenchmarkCropJpeg-8       	      30	  59068572 ns/op
BenchmarkCropPng-8        	      10	 117303259 ns/op
BenchmarkCropWebP-8       	      10	 107060659 ns/op
BenchmarkExtractJpeg-8    	      50	  30708919 ns/op
BenchmarkExtractPng-8     	    3000	    595546 ns/op
BenchmarkExtractWebp-8    	    3000	    386379 ns/op
BenchmarkZoomJpeg-8       	      10	 160005424 ns/op
BenchmarkZoomPng-8        	      30	  44561047 ns/op
BenchmarkZoomWebp-8       	      10	 126732678 ns/op
BenchmarkWatermarkJpeg-8  	      20	  79006133 ns/op
BenchmarkWatermarPng-8    	     200	   8197291 ns/op
BenchmarkWatermarWebp-8   	      30	  49360369 ns/op

Examples

import (
  "fmt"
  "os"
  "github.com/h2non/bimg"
)

Resize

buffer, err := bimg.Read("image.jpg")
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

newImage, err := bimg.NewImage(buffer).Resize(800, 600)
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

size, err := bimg.NewImage(newImage).Size()
if size.Width == 800 && size.Height == 600 {
  fmt.Println("The image size is valid")
}

bimg.Write("new.jpg", newImage)

Rotate

buffer, err := bimg.Read("image.jpg")
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

newImage, err := bimg.NewImage(buffer).Rotate(90)
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

bimg.Write("new.jpg", newImage)

Convert

buffer, err := bimg.Read("image.jpg")
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

newImage, err := bimg.NewImage(buffer).Convert(bimg.PNG)
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

if bimg.NewImage(newImage).Type() == "png" {
  fmt.Fprintln(os.Stderr, "The image was converted into png")
}

Force resize

Force resize operation without perserving the aspect ratio:

buffer, err := bimg.Read("image.jpg")
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

newImage, err := bimg.NewImage(buffer).ForceResize(1000, 500)
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

size := bimg.Size(newImage)
if size.Width != 1000 || size.Height != 500 {
  fmt.Fprintln(os.Stderr, "Incorrect image size")
}

Custom colour space (black & white)

buffer, err := bimg.Read("image.jpg")
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

newImage, err := bimg.NewImage(buffer).Colourspace(bimg.INTERPRETATION_B_W)
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

colourSpace, _ := bimg.ImageInterpretation(newImage)
if colourSpace != bimg.INTERPRETATION_B_W {
  fmt.Fprintln(os.Stderr, "Invalid colour space")
}

Custom options

See Options struct to discover all the available fields

options := bimg.Options{
  Width:        800,
  Height:       600,
  Crop:         true,
  Quality:      95,
  Rotate:       180,
  Interlace:    true,
}

buffer, err := bimg.Read("image.jpg")
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

newImage, err := bimg.NewImage(buffer).Process(options)
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

bimg.Write("new.jpg", newImage)

Watermark

buffer, err := bimg.Read("image.jpg")
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

watermark := bimg.Watermark{
  Text:       "Chuck Norris (c) 2315",
  Opacity:    0.25,
  Width:      200,
  DPI:        100,
  Margin:     150,
  Font:       "sans bold 12",
  Background: bimg.Color{255, 255, 255},
}

newImage, err := bimg.NewImage(buffer).Watermark(watermark)
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

bimg.Write("new.jpg", newImage)

Fluent interface

buffer, err := bimg.Read("image.jpg")
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

image := bimg.NewImage(buffer)

// first crop image
_, err := image.CropByWidth(300)
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

// then flip it
newImage, err := image.Flip()
if err != nil {
  fmt.Fprintln(os.Stderr, err)
}

// save the cropped and flipped image
bimg.Write("new.jpg", newImage)

Debugging

Run the process passing the DEBUG environment variable

DEBUG=bimg ./app

Enable libvips traces (note that a lot of data will be written in stdout):

VIPS_TRACE=1 ./app

You can also dump a core on failure, as John Cuppit said:

g_log_set_always_fatal(
                G_LOG_FLAG_RECURSION |
                G_LOG_FLAG_FATAL |
                G_LOG_LEVEL_ERROR |
                G_LOG_LEVEL_CRITICAL |
                G_LOG_LEVEL_WARNING );

Or set the G_DEBUG environment variable:

export G_DEBUG=fatal-warnings,fatal-criticals

API

See godoc reference for detailed API documentation.

Authors

Credits

People who recurrently contributed to improve bimg in some way.

Thank you!

License

MIT - Tomas Aparicio

views

Issues
  • vendor/github.com/h2non/bimg/image.go:15: undefined: Options

    vendor/github.com/h2non/bimg/image.go:15: undefined: Options

    Hi, I have a problème with go build

    go v1.8 macOS 10.12.4

    vendor/github.com/h2non/bimg/image.go:15: undefined: Options
    vendor/github.com/h2non/bimg/image.go:25: undefined: Options
    vendor/github.com/h2non/bimg/image.go:82: undefined: Gravity
    vendor/github.com/h2non/bimg/image.go:122: undefined: Watermark
    vendor/github.com/h2non/bimg/image.go:135: undefined: Angle
    vendor/github.com/h2non/bimg/image.go:159: undefined: Interpretation
    vendor/github.com/h2non/bimg/image.go:167: undefined: Options
    vendor/github.com/h2non/bimg/image.go:177: undefined: ImageMetadata
    vendor/github.com/h2non/bimg/image.go:183: undefined: Interpretation
    vendor/github.com/h2non/bimg/image.go:199: undefined: ImageSize
    vendor/github.com/h2non/bimg/image.go:25: too many errors
    
    opened by euskadi31 15
  • Adds AVIF support

    Adds AVIF support

    • This adds a new type AVIF to the supported type list if libvips >= 8.9.0 is installed.
    • Calls libheif through libvips with the AV1 compression set to save AVIF images.

    This should fix #353.

    feature request 
    opened by LarsFronius 15
  • Unsupported image format

    Unsupported image format

    I'm using bimg in a function. Whole project is running as a service in a background. My usage is pretty simple.

    After "while" usually anything between 1-2 days, and after processing hips of images (hard to say, but we are talking about 1000-2000 images) .Process(options) function crashes with "Unsupported image format".

    After restart everything is back to normal. I've checked source images - and they are ok, and after restart same image which wasn't recognised correctly is ok. It's super hard to debug because I can't reproduce problem without leaving service for 1-2 days..

    Any clues ? I'm doing something wrong here ?

    
    /**
     * resize image action
     * 
     * @param inBuf []byte image to resize
     * @param w, h int width and height
     * @param c
     */
    func Resize(inBuf []byte, w int, h int, c bool, t, quality int) []byte {
    
        options := bimg.Options{
            Width : w,
            Height : h,
            Crop : c,
            //Embed : true,
            Interpolator : bimg.BICUBIC,
            Gravity: bimg.CENTRE,
            Quality:      quality,
        }
    
        // change image type
        if t > 0 {
            options.Type = bimg.ImageType(t)
        }
    
        image := bimg.NewImage(inBuf)
    
        newImage, err := image.Process(options)
    
    
        if err != nil {
            fmt.Println("failed to process image")
            log.Printf("options: %v", options)
    
            //bimg.VipsDebugInfo()
            fmt.Fprintln(os.Stderr, err)
            LastError = err.Error()
    
        }
    
        return newImage
    }
    
    enhancement help wanted 
    opened by slav123 13
  • Openslide dependency

    Openslide dependency

    When installing VIPS using the provided gist, a dependency on openslide is introduced, and therefore a requirement to run Homebrew as root is also introduced. This is officially "not supported" by Homebrew, and kills the script if you have installed Homebrew as required.

    The failure:

    $ curl -s https://bitbucket.org/api/2.0/snippets/bfitzsimmons/AaAk/52663c0a731eebeac46bd60bb2d9b1e7916417c2/files/vips_install | sudo bash -
    Could not find libvips using a PKG_CONFIG_PATH of '/usr/lib/pkgconfig:/usr/local/Library/ENV/pkgconfig/10.10::/usr/local/lib/pkgconfig:/usr/lib/pkgconfig'
    Detected Mac OS
    Installing libvips via homebrew
    Error: Cowardly refusing to `sudo brew install`
    You can use brew with sudo, but only if the brew executable is owned by root.
    However, this is both not recommended and completely unsupported so do so at
    your own risk.
    

    The reason for the failure (note the password prompt):

    $ brew install Caskroom/cask/xquartz
    ==> Tapping Caskroom/cask
    Cloning into '/usr/local/Library/Taps/caskroom/homebrew-cask'...
    ...
    ==> Checking out tag v0.54.0
    🍺  /usr/local/Cellar/brew-cask/0.54.0: 2634 files, 10M, built in 4 seconds
    ==> brew cask install Caskroom/cask/xquartz
    ==> We need to make Caskroom for the first time at /opt/homebrew-cask/Caskroom
    ==> We'll set permissions properly so we won't need sudo in the future
    Password:
    ...
    🍺  xquartz staged at '/opt/homebrew-cask/Caskroom/xquartz/2.7.7' (64M)
    

    I know that the gist is coming from the sharp project, but if bimg does not require openslide, should a new gist be created that avoids the dependency? Perhaps a modification of the current one?

    question 
    opened by bfitzsimmons 10
  • Adding GIF, PDF and SVG support (libvips 8.3)

    Adding GIF, PDF and SVG support (libvips 8.3)

    Heya, after a long pause, I'm back at it and it seems that libvips now support reading GIF and PDF.

    What do you think of this?

    Cheers,

    source of the gif: http://media.photobucket.com/user/jacobseric/media/publicdomain.gif.html

    Issue:

    • [x] libvips requires a version of poppler that isn't present into travis to be compiled with pdf support
    feature request 
    opened by greut 10
  • Tests importing bimg are failing.

    Tests importing bimg are failing.

    When running the following (dramatically simplified) test things blow up a bit.

    package darkroom
    
    import (
        "fmt"
        "testing"
    
        "github.com/h2non/bimg"
    )
    
    func TestGravity(t *testing.T) {
        testData := []struct {
            input  string
            output bimg.Gravity
        }{
            {"center", bimg.CENTRE},
            {"north", bimg.NORTH},
            {"south", bimg.SOUTH},
            {"east", bimg.EAST},
            {"west", bimg.WEST},
        }
        fmt.Println(testData)
    }
    
    $ go test
    # testmain
    /usr/local/Cellar/go/1.5.1/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
    duplicate symbol _interpolator_window_size in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_affine_interpolator in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_colourspace_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_colourspace_issupported_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_embed_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_enable_cache_set_trace in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_enum_nick_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_exif_orientation in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_extract_area_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_flip_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_image_guess_interpretation_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_init_image in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_jpegload_buffer_shrink in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_jpegsave_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_pngsave_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_rotate in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_shrink_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_watermark in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_watermark_replicate in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_webpsave_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    duplicate symbol _vips_zoom_bridge in:
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000001.o
        /var/folders/ps/jyf857wx7s10p80vttjspnh80000gv/T/go-link-836730646/000002.o
    ld: 21 duplicate symbols for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    FAIL    bitbucket.org/bfitzsimmons/darkroom [build failed]
    

    This only occurs when running a test. Compiling and running an app which uses the lib. works as intended.

    help wanted 
    opened by bfitzsimmons 10
  • support vips_resize

    support vips_resize

    vips_resize used by vipsthumbnail seemingly produce smaller size files

    enhancement 
    opened by ingardm 9
  • Use vips reduce when downscaling

    Use vips reduce when downscaling

    I'm scaling an image down by about half and it seems bimg is using vips_affine to do the downscaling, which results in really aliased images: image

    Instead I've swapped it to use vips_reduce when downscaling: image

    I think this would fix https://github.com/h2non/bimg/issues/94

    opened by vektah 9
  • Gaussian Blur

    Gaussian Blur

    Hi @h2non

    This is a PR to add support for Gaussian Blur. As always, there's a big difference between < 7.41 and >= 7.42. I've tested with 7.40, works great, but I cannot test right now with 7.42 (I'll try in a docker soon).

    Quick information on the PR:

    • Maybe the way I've added the options are not the best, let me know how exactly you want it
    • before 7.42, only one parameter (radius int), after, two parameters (sigma, min_ampl double)
    • I've plugged the call in the transformImage and shouldTransformImage, maybe you want it elsewhere
    • I used the vips_gaussblur method, maybe using a mask is more effective ? that could be something to test
    • No test/bench right now, but I'll add it later, just opening the PR to get a feedback on previous points
    • No documentation yet, same as above, I'll add it later once we are OK on the code itself

    It's not tested on vips >= 7.42, so any feedback on that will be of great help!

    Thanks!

    opened by zllak 9
  • Fix for memory issue when watermarking images

    Fix for memory issue when watermarking images

    I rewrote the image watermarking because of the related memory issue I had. See also #138.

    Few remarks:

    • not sure what the specs are for watermarking, I took another approach to watermark an image with another image. Could be that it is not according the specs.

    • ~~when running the test (on OSX) I get an error regarding defering a C-pointer:~~

    • I run some benchmarks already available see the differences below. Benchmarks (ran on OSX, local machine):

    // New implementation
    BenchmarkWatermarkJpeg-4        	      20	  60215874 ns/op
    BenchmarkWatermarPng-4          	     500	   3406345 ns/op
    BenchmarkWatermarWebp-4         	      30	  40243090 ns/op
    BenchmarkWatermarkImageJpeg-4   	      20	  72954939 ns/op
    BenchmarkWatermarImagePng-4     	      30	  38325610 ns/op
    BenchmarkWatermarImageWebp-4    	      20	  70658176 ns/op
    
    // Previous implementation
    BenchmarkWatermarkJpeg-4        	      20	  60050577 ns/op
    BenchmarkWatermarPng-4          	     500	   3385920 ns/op
    BenchmarkWatermarWebp-4         	      30	  39207303 ns/op
    BenchmarkWatermarkImageJpeg-4   	      10	 148488564 ns/op
    BenchmarkWatermarImagePng-4     	      30	  47970915 ns/op
    BenchmarkWatermarImageWebp-4    	      20	  66507471 ns/op
    
    • good news is that the memory issues are solved, and I can use this library to watermark images 👍
    enhancement 
    opened by ajdevries 9
  • Avif benchmarks

    Avif benchmarks

    The benchmarks seem to be outdated, and the code to run them is not built into the Repository like it is with imaginary, I'd like to know how much over head supporting Avif is vs. webp for my image API. I've read it's very CPU heavy and possibly imperformant for a live image transform service

    opened by angelo-hub 0
  • Add TrimBackground as an argument + go.mod + fix pointer bug [Proposal]

    Add TrimBackground as an argument + go.mod + fix pointer bug [Proposal]

    1. Use case: when using Vips_find_trim (for the Trim: true the last argument is the "background" and any alpha channel is looked at as the background argument. In this case you may want to keep the alpha channel but pass it an argument that's a bright easily edge-able color (similar to a green screen). When using the regular Background argument in this case it will flatten alpha channels to that background color when we want to keep alpha channel transparency. [Added in a way that maintains backwards compatibility with the existing API]

    2. adds unit testing for this new options

    3. adds a trim padding option to allow

    4. this also removes a unset pointer that was causing crashes when running trim operations at 30 RPS

    5. add go.mod for modern module support

    I can and would break these out into different branches and you guys can pick which features if any you want out of them but I'd highly recommend merging 1,2 and 4. 3 is more of a nice to have feature for our use case.

    opened by angelo-hub 0
  • error: unknown type name 'uid_t'; did you mean 'pid_t'

    error: unknown type name 'uid_t'; did you mean 'pid_t'

    Hey! When I try to build my go code for windows over the m1 mac I get this error:

    # github.com/h2non/bimg
    In file included from /opt/homebrew/Cellar/glib/2.68.4/include/glib-2.0/gio/gio.h:46,
                     from /opt/homebrew/Cellar/vips/8.11.3/include/vips/vips.h:90,
                     from ../../../../../pkg/mod/github.com/h2non/[email protected]/metadata.go:5:
    /opt/homebrew/Cellar/glib/2.68.4/include/glib-2.0/gio/gcredentials.h:76:1: error: unknown type name 'uid_t'
       76 | uid_t            g_credentials_get_unix_user      (GCredentials    *credentials,
          | ^~~~~
    /opt/homebrew/Cellar/glib/2.68.4/include/glib-2.0/gio/gcredentials.h:80:52: error: unknown type name 'uid_t'; did you mean 'pid_t'?
       80 |                                                    uid_t           uid,
          |                                                    ^~~~~
          |                                                    pid_t
    

    Command for build: ❯ env GOOS="windows" GOARCH="amd64" CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" go build

    opened by vallezw 0
  • GIF conversion: Unsupported image output type

    GIF conversion: Unsupported image output type

    Go version 1.17 GCC version 11.1.0 Vips version 8.11.3

    code sample

    package main
    
    import (
        "log"
        "github.com/h2non/bimg"
    )
    
    func main() {
        buffer, err := bimg.Read("/test.gif")
    
        if err != nil {
            log.Fatal(err)
        }
    
        image := bimg.NewImage(buffer)
    
        options := bimg.Options {
            Width: 64,
            Height: 64,
            Crop: true,
            Quality: 90,
        }
    
        buffer, err = image.Process(options)
    
        if err != nil {
            log.Fatal(err)
        }
    
        if err = bimg.Write("/test_cropped.gif", buffer); err != nil {
            log.Fatal(err)
        }
    }
    

    output Unsupported image output type

    There something to installing vips which isn't reflected in the documentation but hinted at here?

    if [email protected]+ is compiled with proper library bindings

    Edit: For context this is happening on both my local Arch Linux machine and an Alpine Docker Image we are trying to build. Both setups have vips versions of 8.10+ installed.

    opened by kim-hetrifi 0
  • pdf conversion issue

    pdf conversion issue

    trying to create image from pdf file but getting error

    bimg vsn github.com/h2non/bimg v1.1.5 vips vsn 8.11.2

    buffer, _ := bimg.Read(filepath)
    bytes, err := bimg.NewImage(buffer).Convert(bimg.JPEG)
    if err != nil {
    	log.Error().Msgf("pdf error: ", err)
    }
    

    pdf error: %!(EXTRA *errors.errorString=Unsupported image format)

    installed deps

    zlib libxml2 glib gobject-introspection \
        libjpeg-turbo libexif lcms2 fftw giflib libpng \
        libwebp orc tiff poppler-glib poppler-utils librsvg libgsf openexr \
        libheif libimagequant pango pango-tools imagemagick imagemagick6 \
        zlib-dev libxml2-dev glib-dev gobject-introspection-dev \
        libjpeg-turbo-dev libexif-dev lcms2-dev fftw-dev giflib-dev libpng-dev \
        libwebp-dev orc-dev tiff-dev poppler-dev librsvg-dev libgsf-dev openexr-dev \
        libheif-dev libimagequant-dev pango-dev imagemagick-dev pangomm-dev \
        py-gobject3-dev g++ pkgconf\
    

    could someone help me with this issue

    opened by dubrovine 0
  • Question: is it possible to statically compile all dependencies into a single standalone binary?

    Question: is it possible to statically compile all dependencies into a single standalone binary?

    Hello!

    I have installed vips following the recommendations and I would like if possible to deploy a binary containing all the dependencies so that is it possible to deploy it in an AWS Lambda.

    I've tried this in order to compile statically (first time doing so, I do not know exactly if it is ok) but I found some errors.

    env CGO_ENABLED=0 GOOS=linux go build -a -o imgcomps
    # github.com/h2non/bimg
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:93:49: undefined: Gravity
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:133:29: undefined: Watermark
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:139:34: undefined: WatermarkImage
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:152:26: undefined: Angle
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:181:31: undefined: Interpretation
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:202:27: undefined: Options
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:212:29: undefined: ImageMetadata
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:218:35: undefined: Interpretation
    ../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:234:25: undefined: ImageSize
    ../../../go/pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: undefined: Options
    ../../../go/pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: too many errors
    

    I'm using go version GOVERSION="go1.16.2" under Linux Mint.

    In case that this is not possible, should I look into the possibility of installing vips and compiling my app insde a lambda aws docker image?

    Thank you so much for your work and time!

    opened by juan88 1
  • Support brightness and contrast

    Support brightness and contrast

    Hello. I needed support for brightness and contrast. So I decided to add it to bimg. I hope I did everything right.

    opened by Mereng 0
  • Support vips functions that operate on multiple images

    Support vips functions that operate on multiple images

    Adds initial support for vips_FUNCTIONS that operate on multi files, like: vips_arrayjoin (this is the one I needed), vips_mosaic, vips_composite, vips_composite2.

    // See tests for complete example
    buffer, err := NewImageFrom(images, outputOptions).ArrayJoin(opts)
    

    I didn't spend too much time on it, since I don't know if this is something the authors are open too, or whether this project is still active...

    opened by ryanlath 0
  • Alpine Linux ld link error when using libheif 1.12

    Alpine Linux ld link error when using libheif 1.12

    After this alpine linux upgrade which upgrade libheif from 1.11 to 1.12 and go from 1.16.4 to 1.16.5, the github.com/h2non/bimg package cannot no longer compile due to LD/linking error?

    bash-5.1# apk upgrade
    (1/7) Upgrading libcurl (7.76.1-r0 -> 7.77.0-r0)
    (2/7) Upgrading go (1.16.4-r0 -> 1.16.5-r0)
    (3/7) Upgrading libxml2 (2.9.10-r6 -> 2.9.10-r7)
    (4/7) Upgrading libheif (1.11.0-r0 -> 1.12.0-r0)
    (5/7) Upgrading libheif-dev (1.11.0-r0 -> 1.12.0-r0)
    (6/7) Upgrading libxml2-dev (2.9.10-r6 -> 2.9.10-r7)
    (7/7) Upgrading libxml2-utils (2.9.10-r6 -> 2.9.10-r7)
    
    # github.com/h2non/bimg
    /usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libheif.so.1: undefined reference to `de265_get_image_full_range_flag'
    /usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libheif.so.1: undefined reference to `de265_get_image_transfer_characteristics'
    /usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libheif.so.1: undefined reference to `de265_get_image_colour_primaries'
    /usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libheif.so.1: undefined reference to `de265_get_image_matrix_coefficients'
    collect2: error: ld returned 1 exit status
    

    I checked the libheif 1.12 change log and it not see major updates to the code.

    Any help is appreciated. Thanks.

    Cross posted to libheif issues since not sure if issue is libheif or bimg https://github.com/strukturag/libheif/issues/518

    opened by diegomontoya 0
  • Failed `go get` with go 1.16.4, works-ish with 1.16.3

    Failed `go get` with go 1.16.4, works-ish with 1.16.3

    Here's a problem I encountered when importing bimg. I tried with 2 different go versions, 2 tries each:

    • latest official release
    • forcefully pulling the master branch

    Results are reported below.

    go version: 1.16.3

    Command: go get github.com/h2non/bimg Result: OK

    Command: go get github.com/h2non/[email protected] Result: go build github.com/h2non/bimg: invalid flag in pkg-config --cflags: [email protected]/[email protected]/include

    go version: 1.16.4

    Command: go get github.com/h2non/bimg Result: go build github.com/h2non/bimg: invalid flag in pkg-config --cflags: [email protected]/[email protected]/include

    Command: go get github.com/h2non/[email protected] Result: go build github.com/h2non/bimg: invalid flag in pkg-config --cflags: [email protected]/[email protected]/include

    OS info

    ArchLinux Go versions: I tried 1.16.3 and 1.16.4

    opened by RcrdBrt 1
Releases(v1.1.5)
  • v1.1.5(Nov 21, 2020)

  • v1.1.3(Aug 4, 2020)

    v1.1.3 / 2020-08-04

    • fix(ci): disable <8.7 libvips
    • feat: autorotate
    • feat: bump version
    • Merge pull request #347 from vansante/master
    • Merge pull request #345 from fredeastside/more_exif_data
    • add more exif data to metadata
    • Merge pull request #3 from laurentiuilie/add-support-for-heifs-file
    • add brands heis, hevc
    • Merge pull request #2 from laurentiuilie/add-support-for-heifs-file
    • add test image for heifs
    • remove test file and add the check
    • add support for HEIFS file
    • fix(palette): indentation
    • Merge pull request #337 from theplant/master
    • support Palette option for png
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jun 7, 2020)

    v1.1.0 / 2020-06-07

    • feat(ci): enable libvips versions
    • fix(ci)
    • fix(ci)
    • fix(ci): try exporting env vars
    • fix
    • feat: add Dockerfile / Docker-driven CI job
    • fix(co)
    • feat(version): bump minor to 1
    • fix(ci): try new install
    • fix(ci): try new install
    • fix(ci): add curl package
    • fix(ci): add curl package
    • fix(ci): add curl package
    • fix(ci): try new install
    • fix(ci): indent style
    • fix(ci): indent style
    • fix(ci): indent style
    • Merge pull request #299 from evanoberholster/master
    • refactor(ci): disable verions matrix
    • refactor(docs): use github.com package import path
    • feat: add test image
    • Merge pull request #281 from pohang/skip_smartcrop
    • Merge pull request #317 from larrabee/master
    • Merge pull request #307 from OrderMyGear/eslam/ch15924/some-product-images-have-a-border
    • refactor(travis): adjust matrix versions
    • Merge pull request #333 from simia-tech/master
    • Fix orientation in vipsFlip call (resizer rotateAndFlipImage)
    • chore(docs): delete old contributor
    • enable vipsAffine to use Extend option value and send it to lipvips this will change the default from the one that lipvips use which is background to the ones that bimg use which is C.VIPS_EXTEND_BLACK but because the lip add extra 1 or .5 pix the background is considered black anyway so this will not affect anyone but will fix the bug of having border on the right and bottom of some images
    • Merge pull request #327 from shoreward/master
    • update libvips documentation links
    • fix(vips.h): delete preprocessor HEIF version check
    • Merge pull request #320 from cgroschupp/feat/reduce-png-save-size
    • use VIPS_FOREIGN_PNG_FILTER_ALL in vips_pngsave_bridge
    • fix(resizer): add exported error comment
    • Merge branch 'master' of https://github.com/h2non/bimg
    • chore(ci): temporarily disable go/libvips versions
    • Merge pull request #291 from andrioid/patch-1
    • Merge pull request #293 from team-lab/gammaFilter
    • Merge pull request #315 from vansante/heif
    • feat(version): bump patch
    • Fix bug with images with alpha channel on embeding background
    • Fix typo
    • Dont upgrade version, add missing test file
    • Add support for other HEIF mimetype
    • Supporting auto rotate for HEIF/HEIC images.
    • Adding support for heif (i.e. heic files).
    • Merge branch 'master' into master
    • feat(travis): add libvips 8.6.0 matrix
    • GammaFilter
    • Adds support to Elementary OS Loki
    • Add min dimension logic to smartcrop
    • Merge pull request #271 from Dynom/ImprovingAreaWidthTestCoverage
    • Adding a test case that verifies #250
    • Bumping versions in preinstall script
    • Update Transform ICC Profiles with Input Profile
    Source code(tar.gz)
    Source code(zip)
  • v1.0.19(Mar 26, 2020)

  • v1.0.18(Dec 22, 2017)

    Changes

    v1.0.18 / 2017-12-22

    • Merge pull request #216 from Bynder/master
    • Merge pull request #208 from mikestead/feature/webp-lossless
    • Remove go-debug usage
    • refactor(docs): remove codesponsor :(
    • fix(options): use float64 type in Options.Threshold
    • Merge pull request #206 from tstm/add-trim-options
    • Add lossless option for saving webp
    • Set the test file to write its own file
    • Add the option to use background and threshold options on trim
    Source code(tar.gz)
    Source code(zip)
  • v1.0.17(Dec 22, 2017)

    Changes

    v1.0.17 / 2017-11-14

    • refactor(resizer): remove fmt statement
    • fix(type_test): use string formatting
    • Merge pull request #207 from traum-ferienwohnungen/nearest-neighbour
    • Add nearest-neighbour interpolation
    • Merge pull request #203 from traum-ferienwohnungen/fix_icc_memory_leak
    • Fix memory leak on icc_transform
    Source code(tar.gz)
    Source code(zip)
  • v1.0.15(Oct 5, 2017)

    Changes

    v1.0.15 / 2017-10-05

    • Merge pull request #198 from greut/webpload
    • Add shrink-on-load for webp.
    • Merge pull request #197 from greut/typos
    • Small typo.
    • feat(docs): add codesponsor
    Source code(tar.gz)
    Source code(zip)
  • v1.0.14(Sep 12, 2017)

    Changes

    v1.0.14 / 2017-09-12

    • Merge pull request #192 from greut/trim
    • Adding trim operation.
    • Merge pull request #191 from greut/alpha4
    • Update 8.6 to alpha4.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.10(Jun 26, 2017)

    v1.0.10 / 2017-06-25

    • Merge pull request #164 from greut/length
    • Add Image.Length()
    • Merge pull request #163 from greut/libvips856
    • Run libvips 8.5.6 on Travis.
    • Merge pull request #161 from henry-blip/master
    • Expose vips cache memory management functions.
    • feat(docs): add watermark image note in features
    Source code(tar.gz)
    Source code(zip)
A lightning fast image processing and resizing library for Go

govips A lightning fast image processing and resizing library for Go This package wraps the core functionality of libvips image processing library by

David Byttow 521 Oct 22, 2021
Fast and secure standalone server for resizing and converting remote images

imgproxy imgproxy is a fast and secure standalone server for resizing and converting remote images. The main principles of imgproxy are simplicity, sp

imgproxy 5.2k Oct 23, 2021
Storage and image processing server written in Go

Mort An S3-compatible image processing server written in Go. Still in active development. Features HTTP server Resize, Rotate, SmartCrop Convert (JPEG

Marcin Kaciuba 436 Oct 7, 2021
Imaging is a simple image processing package for Go

Imaging Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.). All the image process

Grigory Dryapak 4k Oct 18, 2021
An image resizing server written in Go

picfit picfit is a reusable Go server to manipulate images (resize, thumbnail, etc.). It will act as a proxy on your storage engine and will be served

Florent Messa 1.6k Oct 20, 2021
A cross-platform tool to convert images into ascii art and print them on the console

A cross-platform tool to convert images into ascii art and print them on the console

Zoraiz Hassan 501 Oct 17, 2021
Go Image Filtering Toolkit

GO IMAGE FILTERING TOOLKIT (GIFT) Package gift provides a set of useful image processing filters. Pure Go. No external dependencies outside of the Go

Grigory Dryapak 1.5k Oct 17, 2021
A library for playing with colors in go (golang).

go-colorful A library for playing with colors in Go. Supports Go 1.13 onwards. Why? I love games. I make games. I love detail and I get lost in detail

Lucas Beyer 898 Oct 18, 2021
Resize images and animated GIFs in Go

Lilliput relies on mature, high-performance C libraries to do most of the work of decompressing, resizing and compressing images. It aims to do as little memory allocation as possible and especially not to create garbage in Go. As a result, it is suitable for very high throughput image resizing services.

Discord 1.7k Oct 13, 2021
Pure golang image resizing

This package is no longer being updated! Please look for alternatives if that bothers you. Resize Image resizing for the Go programming language with

Jan Schlicht 2.7k Oct 14, 2021
Content aware image resize library

Caire is a content aware image resize library based on Seam Carving for Content-Aware Image Resizing paper. How does it work An energy map (edge detec

Endre Simo 9.7k Oct 21, 2021
go library for image programming (merge, crop, resize, watermark, animate, ease, transit)

Result Terminal Code mergi -t TT -i https://raw.githubusercontent.com/ashleymcnamara/gophers/master/Facepalm_Gopher.png -r "131 131" -i https://raw.gi

Noel Yahan 154 Oct 5, 2021
:foggy: Convert image to ASCII

?? Image2ascii Image2ASCII is a library that converts images into ASCII images and provides command-line tools for easy use. Installation go get githu

秦世成 587 Oct 11, 2021
accelerated-container-image

Accelerated Container Image Accelerated Container Image is an open-source implementation of paper "DADI: Block-Level Image Service for Agile and Elast

Alibaba 150 Oct 20, 2021
Image processing library and rendering toolkit for Go.

blend Image processing library and rendering toolkit for Go. (WIP) Installation: This library is compatible with Go1. go get github.com/phrozen/blend

Guillermo Estrada 60 Sep 13, 2021
Image processing algorithms in pure Go

bild A collection of parallel image processing algorithms in pure Go. The aim of this project is simplicity in use and development over absolute high

Anthony N. Simon 3.4k Oct 17, 2021
Convert images to computer generated art using delaunay triangulation.

▲ Triangle is a tool for generating triangulated image using delaunay triangulation. It takes a source image and converts it to an abstract image comp

Endre Simo 1.8k Oct 23, 2021
Super fast static photo and video gallery generator (written in Go and HTML/CSS/native JS)

fastgallery Fast static photo and video gallery generator Super fast (written in Go and C, concurrent, uses fastest image/video libraries, 4-8 times f

Toni Melisma 20 Jul 13, 2021
Go package captcha implements generation and verification of image and audio CAPTCHAs.

Package captcha ⚠️ Warning: this captcha can be broken by advanced OCR captcha breaking algorithms. import "github.com/dchest/captcha" Package captch

Dmitry Chestnykh 1.5k Oct 20, 2021