From cf75e90e480c3685e24d206028d68f548d829d68 Mon Sep 17 00:00:00 2001 From: Kishor Gandham Date: Wed, 17 Jan 2018 11:52:57 +0530 Subject: [PATCH 01/12] Fix image crop during embed --- resizer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resizer.go b/resizer.go index ddd4127..eaf5df5 100644 --- a/resizer.go +++ b/resizer.go @@ -446,7 +446,11 @@ func imageCalculations(o *Options, inWidth, inHeight int) float64 { switch { // Fixed width and height case o.Width > 0 && o.Height > 0: - factor = math.Min(xfactor, yfactor) + if o.Crop { + factor = math.Min(xfactor, yfactor) + } else { + factor = math.Max(xfactor, yfactor) + } // Fixed width, auto height case o.Width > 0: if o.Crop { From 70672d35e37d10bbf5cc9725f3d72231b0ee2c9b Mon Sep 17 00:00:00 2001 From: Adriano Date: Sat, 19 May 2018 10:36:06 -0400 Subject: [PATCH 02/12] Libvips documentation URL and README copy updates --- README.md | 6 +++--- image.go | 2 +- metadata.go | 2 +- options.go | 4 ++-- vips.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4588758..55efe60 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ bimg was designed to be a small and efficient library supporting a common set of 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](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use) +bimg uses internally libvips, a powerful library written in C for image processing which requires a [low memory footprint](https://github.com/jcupitt/libvips/wiki/Speed_and_Memory_Use) 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](https://github.com/h2non/imaginary). @@ -77,10 +77,10 @@ The [install script](https://github.com/h2non/bimg/blob/master/preinstall.sh) re ## Performance -libvips is probably the faster open source solution for image processing. +libvips is probably the fastest open source solution for image processing. Here you can see some performance test comparisons for multiple scenarios: -- [libvips speed and memory usage](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use) +- [libvips speed and memory usage](https://github.com/jcupitt/libvips/wiki/Speed-and-memory-use) ## Benchmark diff --git a/image.go b/image.go index 093d5a5..224dafa 100644 --- a/image.go +++ b/image.go @@ -203,7 +203,7 @@ func (i *Image) Metadata() (ImageMetadata, error) { } // Interpretation gets the image interpretation type. -// See: http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/VipsImage.html#VipsInterpretation +// See: https://jcupitt.github.io/libvips/API/current/VipsImage.html#VipsInterpretation func (i *Image) Interpretation() (Interpretation, error) { return ImageInterpretation(i.buffer) } diff --git a/metadata.go b/metadata.go index 77eac8c..f6562d6 100644 --- a/metadata.go +++ b/metadata.go @@ -43,7 +43,7 @@ func ColourspaceIsSupported(buf []byte) (bool, error) { } // ImageInterpretation returns the image interpretation type. -// See: http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/VipsImage.html#VipsInterpretation +// See: https://jcupitt.github.io/libvips/API/current/VipsImage.html#VipsInterpretation func ImageInterpretation(buf []byte) (Interpretation, error) { return vipsInterpretationBuffer(buf) } diff --git a/options.go b/options.go index 17a1cb4..c567621 100644 --- a/options.go +++ b/options.go @@ -89,7 +89,7 @@ const ( ) // Interpretation represents the image interpretation type. -// See: http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/VipsImage.html#VipsInterpretation +// See: https://jcupitt.github.io/libvips/API/current/VipsImage.html#VipsInterpretation type Interpretation int const ( @@ -119,7 +119,7 @@ const ( // Extend represents the image extend mode, used when the edges // of an image are extended, you can specify how you want the extension done. -// See: http://www.vips.ecs.soton.ac.uk/supported/8.4/doc/html/libvips/libvips-conversion.html#VIPS-EXTEND-BACKGROUND:CAPS +// See: https://jcupitt.github.io/libvips/API/current/libvips-conversion.html#VIPS-EXTEND-BACKGROUND:CAPS type Extend int const ( diff --git a/vips.go b/vips.go index fb17901..0126a24 100644 --- a/vips.go +++ b/vips.go @@ -572,7 +572,7 @@ func vipsReduce(input *C.VipsImage, xshrink float64, yshrink float64) (*C.VipsIm func vipsEmbed(input *C.VipsImage, left, top, width, height int, extend Extend, background Color) (*C.VipsImage, error) { var image *C.VipsImage - // Max extend value, see: http://www.vips.ecs.soton.ac.uk/supported/8.4/doc/html/libvips/libvips-conversion.html#VipsExtend + // Max extend value, see: https://jcupitt.github.io/libvips/API/current/libvips-conversion.html#VipsExtend if extend > 5 { extend = ExtendBackground } From e3e4ba395e6d1daf26b2e536b54ecb1b7ba3c69b Mon Sep 17 00:00:00 2001 From: Andrey Kirillov Date: Tue, 31 Jul 2018 14:50:43 +0300 Subject: [PATCH 03/12] Fix AreaWidth calculation --- resizer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resizer.go b/resizer.go index 98a95ae..9e13ac3 100644 --- a/resizer.go +++ b/resizer.go @@ -273,7 +273,7 @@ func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) { break case o.Top != 0 || o.Left != 0 || o.AreaWidth != 0 || o.AreaHeight != 0: if o.AreaWidth == 0 { - o.AreaHeight = o.Width + o.AreaWidth = o.Width } if o.AreaHeight == 0 { o.AreaHeight = o.Height From 98902da9c798475f15d4890e2bae06ebf9b985ee Mon Sep 17 00:00:00 2001 From: Dan Persa Date: Fri, 19 Oct 2018 16:28:19 +0200 Subject: [PATCH 04/12] Make it compatible with the latest vips. Fixes #255 --- preinstall.sh | 2 +- vips.go | 2 +- vips.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/preinstall.sh b/preinstall.sh index 33d41fc..9187aa7 100644 --- a/preinstall.sh +++ b/preinstall.sh @@ -1,7 +1,7 @@ #!/bin/bash vips_version_minimum=8.4.2 -vips_version_latest_major_minor=8.5 +vips_version_latest_major_minor=8.7 vips_version_latest_patch=1 vips_version_full="$vips_version_latest_major_minor.$vips_version_latest_patch" diff --git a/vips.go b/vips.go index fb17901..7d45e81 100644 --- a/vips.go +++ b/vips.go @@ -233,7 +233,7 @@ func vipsRotate(image *C.VipsImage, angle Angle) (*C.VipsImage, error) { var out *C.VipsImage defer C.g_object_unref(C.gpointer(image)) - err := C.vips_rotate(image, &out, C.int(angle)) + err := C.vips_rotate_bimg(image, &out, C.int(angle)) if err != 0 { return nil, catchVipsError() } diff --git a/vips.h b/vips.h index 29a2e63..e0d623a 100644 --- a/vips.h +++ b/vips.h @@ -177,7 +177,7 @@ vips_type_find_save_bridge(int t) { } int -vips_rotate(VipsImage *in, VipsImage **out, int angle) { +vips_rotate_bimg(VipsImage *in, VipsImage **out, int angle) { int rotate = VIPS_ANGLE_D0; angle %= 360; From d8266667dc86e9ee691f38bea6aee5495e1e00ac Mon Sep 17 00:00:00 2001 From: golint fixer Date: Wed, 24 Oct 2018 15:46:04 -0500 Subject: [PATCH 05/12] Fix golint import path --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3bb39f4..e9bb390 100644 --- a/.travis.yml +++ b/.travis.yml @@ -89,7 +89,7 @@ before_install: - vips --vips-version install: - - go get -u github.com/golang/lint/golint + - go get -u golang.org/x/lint/golint script: - diff -u <(echo -n) <(gofmt -s -d ./) From f933e6f6a3f4d04454f4bad4fe795969b73d65c6 Mon Sep 17 00:00:00 2001 From: c93614 Date: Sat, 17 Nov 2018 03:18:14 +0000 Subject: [PATCH 06/12] Updated the libvips tarbal_url and also updated the vips version --- preinstall.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/preinstall.sh b/preinstall.sh index 33d41fc..2443290 100644 --- a/preinstall.sh +++ b/preinstall.sh @@ -1,15 +1,15 @@ #!/bin/bash vips_version_minimum=8.4.2 -vips_version_latest_major_minor=8.5 -vips_version_latest_patch=1 +vips_version_latest_major_minor=8.6 +vips_version_latest_patch=5 vips_version_full="$vips_version_latest_major_minor.$vips_version_latest_patch" openslide_version_minimum=3.4.0 openslide_version_latest_major_minor=3.4 openslide_version_latest_patch=1 -tarbal_url="https://github.com/jcupitt/libvips/releases/download/v$vips_version_full/vips-$vips_version_full.tar.gz" +tarbal_url="https://github.com/libvips/libvips/releases/download/v$vips_version_full/vips-$vips_version_full.tar.gz" install_libvips_from_source() { # Download tarball @@ -156,7 +156,7 @@ if [ $enable_openslide -eq 1 ] && [ -z $vips_with_openslide ] && [ $openslide_ex # RHEL/CentOS 7 echo "Installing libopenslide dependencies via yum" yum groupinstall -y "Development Tools" - yum install -y tar curl libpng-devel libjpeg-devel libxml2-devel zlib-devel openjpeg-devel libtiff-devel gdk-pixbuf2-devel sqlite-devel cairo-devel glib2-devel + yum install -y tar curl libpng-devel libjpeg-devel libxml2-devel zlib-devel openjpeg-devel libtiff-devel gdk-pixbuf2-devel sqlite-devel cairo-devel glib2-devel expat-devel install_libopenslide_from_source "--prefix=/usr" ;; "Red Hat Enterprise Linux release 6."*|"CentOS release 6."*|"Scientific Linux release 6."*) From f6430b1b26acc70a5b4e611b91cfd9d38714306c Mon Sep 17 00:00:00 2001 From: BernhardB Date: Sun, 18 Nov 2018 13:52:23 +0100 Subject: [PATCH 07/12] add support for Debian 9 to preinstall.sh --- preinstall.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/preinstall.sh b/preinstall.sh index d19f09a..53d65c9 100644 --- a/preinstall.sh +++ b/preinstall.sh @@ -125,8 +125,8 @@ if [ $enable_openslide -eq 1 ] && [ -z $vips_with_openslide ] && [ $openslide_ex DISTRO=$(lsb_release -c -s) echo "Detected Debian Linux '$DISTRO'" case "$DISTRO" in - jessie|vivid|wily|xenial) - # Debian 8, Ubuntu 15 + jessie|vivid|wily|xenial|stretch) + # Debian 9, Debian 8, Ubuntu 15 echo "Installing libopenslide via apt-get" apt-get install -y libopenslide-dev ;; @@ -215,6 +215,12 @@ if [ -f /etc/debian_version ]; then apt-get install -y automake build-essential gobject-introspection gtk-doc-tools libglib2.0-dev libjpeg-dev libpng12-dev libwebp-dev libtiff5-dev libexif-dev libgsf-1-dev liblcms2-dev libxml2-dev swig libmagickcore-dev curl install_libvips_from_source ;; + stretch) + # Debian 9 + echo "Installing libvips dependencies via apt-get" + apt-get install -y automake build-essential gobject-introspection gtk-doc-tools libglib2.0-dev libjpeg-dev libpng-dev libwebp-dev libtiff5-dev libexif-dev libgsf-1-dev liblcms2-dev libxml2-dev swig libmagickcore-dev curl + install_libvips_from_source + ;; precise|wheezy|maya) # Debian 7, Ubuntu 12.04, Mint 13 echo "Installing libvips dependencies via apt-get" From bb5ccce171ad10896373c3fc2eb280d5c10595f1 Mon Sep 17 00:00:00 2001 From: BernhardB Date: Thu, 22 Nov 2018 20:53:43 +0100 Subject: [PATCH 08/12] set vips version to 8.6.5 --- preinstall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/preinstall.sh b/preinstall.sh index 53d65c9..639e226 100644 --- a/preinstall.sh +++ b/preinstall.sh @@ -1,8 +1,8 @@ #!/bin/bash vips_version_minimum=8.4.2 -vips_version_latest_major_minor=8.7 -vips_version_latest_patch=1 +vips_version_latest_major_minor=8.6 +vips_version_latest_patch=5 vips_version_full="$vips_version_latest_major_minor.$vips_version_latest_patch" openslide_version_minimum=3.4.0 From 4b9abdb945893c295f0e58b6803102f23e061ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Aparicio?= Date: Sun, 9 Dec 2018 23:37:54 +0100 Subject: [PATCH 09/12] feat(travis): remove old Go versions, add Go 1.11 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e9bb390..7a07053 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,10 @@ dist: trusty sudo: false go: - - "1.6" - - "1.7" - "1.8" - "1.9" - "1.10" + - "1.11" - "tip" env: From 6e42002588fa2ae3854925053d5fd761af8f0b62 Mon Sep 17 00:00:00 2001 From: Mark van der Velden Date: Mon, 10 Dec 2018 22:45:13 +0100 Subject: [PATCH 10/12] Bumping versions in preinstall script --- preinstall.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 preinstall.sh diff --git a/preinstall.sh b/preinstall.sh old mode 100644 new mode 100755 index 639e226..7547f23 --- a/preinstall.sh +++ b/preinstall.sh @@ -1,8 +1,8 @@ #!/bin/bash -vips_version_minimum=8.4.2 -vips_version_latest_major_minor=8.6 -vips_version_latest_patch=5 +vips_version_minimum=8.7.2 +vips_version_latest_major_minor=8.7 +vips_version_latest_patch=2 vips_version_full="$vips_version_latest_major_minor.$vips_version_latest_patch" openslide_version_minimum=3.4.0 From da064bf3993ece588af469a4439e111dd6b875e8 Mon Sep 17 00:00:00 2001 From: Mark van der Velden Date: Wed, 19 Dec 2018 09:53:09 +0100 Subject: [PATCH 11/12] Adding a test case that verifies #250 --- resizer.go | 4 ++++ resizer_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/resizer.go b/resizer.go index 5ba32e1..a8e998c 100644 --- a/resizer.go +++ b/resizer.go @@ -12,6 +12,10 @@ import ( "math" ) +var ( + ErrExtractAreaParamsRequired = errors.New("extract area width/height params are required") +) + // resizer is used to transform a given image as byte buffer // with the passed options. func resizer(buf []byte, o Options) ([]byte, error) { diff --git a/resizer_test.go b/resizer_test.go index a4b54b0..6a116a2 100644 --- a/resizer_test.go +++ b/resizer_test.go @@ -364,6 +364,54 @@ func TestExtractCustomAxis(t *testing.T) { Write("testdata/test_extract_custom_axis_out.jpg", newImg) } +func TestExtractOrEmbedImage(t *testing.T) { + buf, _ := Read("testdata/test.jpg") + input, _, err := loadImage(buf) + if err != nil { + t.Fatalf("Unable to load image %s", err) + } + + o := Options{ + Top: 10, + Left: 10, + Width: 100, + Height: 200, + + // Fields to test + AreaHeight: 0, + AreaWidth: 0, + + Quality: 100, /* Needs a value to satisfy libvips */ + } + + result, err := extractOrEmbedImage(input, o) + if err != nil { + if err == ErrExtractAreaParamsRequired { + t.Fatalf("Expecting AreaWidth and AreaHeight to have been defined") + } + + t.Fatalf("Unknown error occurred %s", err) + } + + image, err := saveImage(result, o) + if err != nil { + t.Fatalf("Failed saving image %s", err) + } + + test, err := Size(image) + if err != nil { + t.Fatalf("Failed fetching the size %s", err) + } + + if test.Height != o.Height { + t.Errorf("Extract failed, resulting Height %d doesn't match %d", test.Height, o.Height) + } + + if test.Width != o.Width { + t.Errorf("Extract failed, resulting Width %d doesn't match %d", test.Width, o.Width) + } +} + func TestConvert(t *testing.T) { width, height := 300, 240 formats := [3]ImageType{PNG, WEBP, JPEG} From 5a9d7f21d924f0aca7dd1147c262a02e33336ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s?= Date: Wed, 25 Sep 2019 00:15:10 +0200 Subject: [PATCH 12/12] feat(travis): add libvips 8.6.0 matrix --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7a07053..af2d4c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ env: - LIBVIPS=8.4.6 - LIBVIPS=8.5.8 - LIBVIPS=8.6.2 + - LIBVIPS=8.8.0 - LIBVIPS=master matrix: