Merge branch 'master' into master

This commit is contained in:
evanoberholster 2019-10-01 23:59:30 +08:00 committed by GitHub
commit 599dc0ba03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 82 additions and 20 deletions

View file

@ -4,11 +4,10 @@ dist: trusty
sudo: false sudo: false
go: go:
- "1.6"
- "1.7"
- "1.8" - "1.8"
- "1.9" - "1.9"
- "1.10" - "1.10"
- "1.11"
- "tip" - "tip"
env: env:
@ -18,6 +17,7 @@ env:
- LIBVIPS=8.4.6 - LIBVIPS=8.4.6
- LIBVIPS=8.5.8 - LIBVIPS=8.5.8
- LIBVIPS=8.6.2 - LIBVIPS=8.6.2
- LIBVIPS=8.8.0
- LIBVIPS=master - LIBVIPS=master
matrix: matrix:
@ -89,7 +89,7 @@ before_install:
- vips --vips-version - vips --vips-version
install: install:
- go get -u github.com/golang/lint/golint - go get -u golang.org/x/lint/golint
script: script:
- diff -u <(echo -n) <(gofmt -s -d ./) - diff -u <(echo -n) <(gofmt -s -d ./)

View file

@ -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 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. 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). 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 ## 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: 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 ## Benchmark

View file

@ -203,7 +203,7 @@ func (i *Image) Metadata() (ImageMetadata, error) {
} }
// Interpretation gets the image interpretation type. // 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) { func (i *Image) Interpretation() (Interpretation, error) {
return ImageInterpretation(i.buffer) return ImageInterpretation(i.buffer)
} }

View file

@ -43,7 +43,7 @@ func ColourspaceIsSupported(buf []byte) (bool, error) {
} }
// ImageInterpretation returns the image interpretation type. // 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) { func ImageInterpretation(buf []byte) (Interpretation, error) {
return vipsInterpretationBuffer(buf) return vipsInterpretationBuffer(buf)
} }

View file

@ -89,7 +89,7 @@ const (
) )
// Interpretation represents the image interpretation type. // 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 type Interpretation int
const ( const (
@ -119,7 +119,7 @@ const (
// Extend represents the image extend mode, used when the edges // Extend represents the image extend mode, used when the edges
// of an image are extended, you can specify how you want the extension done. // 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 type Extend int
const ( const (

20
preinstall.sh Normal file → Executable file
View file

@ -1,15 +1,15 @@
#!/bin/bash #!/bin/bash
vips_version_minimum=8.4.2 vips_version_minimum=8.7.2
vips_version_latest_major_minor=8.5 vips_version_latest_major_minor=8.7
vips_version_latest_patch=1 vips_version_latest_patch=2
vips_version_full="$vips_version_latest_major_minor.$vips_version_latest_patch" vips_version_full="$vips_version_latest_major_minor.$vips_version_latest_patch"
openslide_version_minimum=3.4.0 openslide_version_minimum=3.4.0
openslide_version_latest_major_minor=3.4 openslide_version_latest_major_minor=3.4
openslide_version_latest_patch=1 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() { install_libvips_from_source() {
# Download tarball # Download tarball
@ -125,8 +125,8 @@ if [ $enable_openslide -eq 1 ] && [ -z $vips_with_openslide ] && [ $openslide_ex
DISTRO=$(lsb_release -c -s) DISTRO=$(lsb_release -c -s)
echo "Detected Debian Linux '$DISTRO'" echo "Detected Debian Linux '$DISTRO'"
case "$DISTRO" in case "$DISTRO" in
jessie|vivid|wily|xenial) jessie|vivid|wily|xenial|stretch)
# Debian 8, Ubuntu 15 # Debian 9, Debian 8, Ubuntu 15
echo "Installing libopenslide via apt-get" echo "Installing libopenslide via apt-get"
apt-get install -y libopenslide-dev apt-get install -y libopenslide-dev
;; ;;
@ -156,7 +156,7 @@ if [ $enable_openslide -eq 1 ] && [ -z $vips_with_openslide ] && [ $openslide_ex
# RHEL/CentOS 7 # RHEL/CentOS 7
echo "Installing libopenslide dependencies via yum" echo "Installing libopenslide dependencies via yum"
yum groupinstall -y "Development Tools" 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" install_libopenslide_from_source "--prefix=/usr"
;; ;;
"Red Hat Enterprise Linux release 6."*|"CentOS release 6."*|"Scientific Linux release 6."*) "Red Hat Enterprise Linux release 6."*|"CentOS release 6."*|"Scientific Linux release 6."*)
@ -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 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 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) precise|wheezy|maya)
# Debian 7, Ubuntu 12.04, Mint 13 # Debian 7, Ubuntu 12.04, Mint 13
echo "Installing libvips dependencies via apt-get" echo "Installing libvips dependencies via apt-get"

View file

@ -12,6 +12,10 @@ import (
"math" "math"
) )
var (
ErrExtractAreaParamsRequired = errors.New("extract area width/height params are required")
)
// resizer is used to transform a given image as byte buffer // resizer is used to transform a given image as byte buffer
// with the passed options. // with the passed options.
func resizer(buf []byte, o Options) ([]byte, error) { func resizer(buf []byte, o Options) ([]byte, error) {
@ -274,7 +278,7 @@ func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) {
break break
case o.Top != 0 || o.Left != 0 || o.AreaWidth != 0 || o.AreaHeight != 0: case o.Top != 0 || o.Left != 0 || o.AreaWidth != 0 || o.AreaHeight != 0:
if o.AreaWidth == 0 { if o.AreaWidth == 0 {
o.AreaHeight = o.Width o.AreaWidth = o.Width
} }
if o.AreaHeight == 0 { if o.AreaHeight == 0 {
o.AreaHeight = o.Height o.AreaHeight = o.Height
@ -444,7 +448,11 @@ func imageCalculations(o *Options, inWidth, inHeight int) float64 {
switch { switch {
// Fixed width and height // Fixed width and height
case o.Width > 0 && o.Height > 0: 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 // Fixed width, auto height
case o.Width > 0: case o.Width > 0:
if o.Crop { if o.Crop {

View file

@ -364,6 +364,54 @@ func TestExtractCustomAxis(t *testing.T) {
Write("testdata/test_extract_custom_axis_out.jpg", newImg) 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) { func TestConvert(t *testing.T) {
width, height := 300, 240 width, height := 300, 240
formats := [3]ImageType{PNG, WEBP, JPEG} formats := [3]ImageType{PNG, WEBP, JPEG}

View file

@ -605,7 +605,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) { func vipsEmbed(input *C.VipsImage, left, top, width, height int, extend Extend, background Color) (*C.VipsImage, error) {
var image *C.VipsImage 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 { if extend > 5 {
extend = ExtendBackground extend = ExtendBackground
} }