Skip to content

Commit

Permalink
support SVG >=10MB (#37)
Browse files Browse the repository at this point in the history
* support SVG >10MB

* moved param to ENV
  • Loading branch information
idanya authored Mar 4, 2021
1 parent f0f6fe3 commit 4ba4d63
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions vips/foreign.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "lang.h"

int load_image_buffer(void *buf, size_t len, int imageType, VipsImage **out) {
int load_image_buffer(void *buf, size_t len, int imageType, gboolean unlimitedSvgSize, VipsImage **out) {
int code = 1;

if (imageType == JPEG) {
Expand All @@ -18,7 +18,7 @@ int load_image_buffer(void *buf, size_t len, int imageType, VipsImage **out) {
} else if (imageType == PDF) {
code = vips_pdfload_buffer(buf, len, out, NULL);
} else if (imageType == SVG) {
code = vips_svgload_buffer(buf, len, out, NULL);
code = vips_svgload_buffer(buf, len, out, "unlimited", unlimitedSvgSize, NULL);
} else if (imageType == HEIF) {
// added autorotate on load as currently it addresses orientation issues
// https://github.com/libvips/libvips/pull/1680
Expand Down
8 changes: 7 additions & 1 deletion vips/foreign.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"image/png"
"math"
"os"
"runtime"
"unsafe"

Expand Down Expand Up @@ -229,7 +230,12 @@ func vipsLoadFromBuffer(buf []byte) (*C.VipsImage, ImageType, error) {
return nil, ImageTypeUnknown, ErrUnsupportedImageFormat
}

if err := C.load_image_buffer(unsafe.Pointer(&src[0]), C.size_t(len(src)), C.int(imageType), &out); err != 0 {
var unlimitedSvgLoad C.gboolean = C.FALSE
if _, exists := os.LookupEnv("UNLIMITED_SVG_LOAD"); exists {
unlimitedSvgLoad = C.TRUE
}

if err := C.load_image_buffer(unsafe.Pointer(&src[0]), C.size_t(len(src)), C.int(imageType), unlimitedSvgLoad, &out); err != 0 {
return nil, ImageTypeUnknown, handleImageError(out)
}

Expand Down
2 changes: 1 addition & 1 deletion vips/foreign.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef enum types {
BMP
} ImageType;

int load_image_buffer(void *buf, size_t len, int imageType, VipsImage **out);
int load_image_buffer(void *buf, size_t len, int imageType, gboolean unlimitedSvgSize, VipsImage **out);

typedef struct SaveParams {
VipsImage *inputImage;
Expand Down

0 comments on commit 4ba4d63

Please sign in to comment.