diff --git a/dist/doc/thumbnailator.xqm.xml b/dist/doc/thumbnailator.xqm.xml index 5d34309..5e353f4 100644 --- a/dist/doc/thumbnailator.xqm.xml +++ b/dist/doc/thumbnailator.xqm.xml @@ -1,6 +1,6 @@ - 2017-04-21T15:03:58.643+01:00 + 2017-04-29T22:28:45.705+01:00 1.1 @@ -10,20 +10,47 @@ Generate image thumbnails using the thumbnailator library. https://github.com/coobird/thumbnailator andy bunce - 4.4.1 + 0.5 + - + + + org.expkgzone58.image.Thumbs + + + + + generate scaled version of source image with maximum dimension of size + $source base64Binary (streamed?) e.g from `fetch:binary` + base64Binary for thumbnail + + thumbnails:size + declare function thumbnails:size($source as xs:base64Binary, $size as xs:integer) as xs:base64Binary + + + source + xs:base64Binary + + + size + xs:integer + + + + xs:base64Binary + + generate scaled version of source image with maximum dimension of size $source base64Binary (streamed?) e.g from `fetch:binary` - base64Binary for thumbnail + base64Binary for thumbnail thumbnails:size declare function thumbnails:size($source as xs:base64Binary, $width as xs:integer, $height as xs:integer) as xs:base64Binary @@ -45,14 +72,36 @@ xs:base64Binary + + + generate scaled version of source image at given factors 0-1 + $source base64Binary (streamed?) e.g from `fetch:binary` + the thumbnail + + thumbnails:scale + declare function thumbnails:scale($source as xs:base64Binary, $scale as xs:double) as xs:base64Binary + + + source + xs:base64Binary + + + scale + xs:double + + + + xs:base64Binary + + generate scaled version of source image at given factors 0-1 $source base64Binary (streamed?) e.g from `fetch:binary` - base64Binary for thumbnail + the thumbnail thumbnails:scale - declare function thumbnails:scale($source as xs:base64Binary, $xscale as xs:float, $yscale as xs:float) as xs:base64Binary + declare function thumbnails:scale($source as xs:base64Binary, $xscale as xs:double, $yscale as xs:double) as xs:base64Binary source @@ -60,11 +109,11 @@ xscale - xs:float + xs:double yscale - xs:float + xs:double @@ -76,7 +125,7 @@ generate thumbnail using parameters specified via XML $source base64Binary (streamed?) e.g from `fetch:binary` $task XML parameters <task><size width="100" .. - base64Binary for thumbnail + the thumbnail thumbnails:task declare function thumbnails:task($source as xs:base64Binary, $task as element(thumbnail)) as xs:base64Binary @@ -96,9 +145,31 @@ - validate task XML against schema - $src XML parameters <task><size width="100" .. - validation report + validate task thumbnail XML against schema + $src XML parameters <thumbnail><size width="100" .. + empty-sequence or error + BXVA0001: the validation fails. + BXVA0002: the validation process cannot be started. + BXVA0003: no XML Schema validator is available. + BXVA0004: no validator is found for the specified version. + + thumbnails:validate + declare function thumbnails:validate($src as item()*) as empty-sequence() + + + src + item() + + + + empty-sequence() + + + + + validate task thumbnail XML against schema + $src XML parameters <thumbnail><size width="100" .. + validation report thumbnails:validation-report declare function thumbnails:validation-report($src as item()*) as element(report) diff --git a/dist/thumbnailator-4.1.5.xar b/dist/thumbnailator-5.0.11.xar similarity index 88% rename from dist/thumbnailator-4.1.5.xar rename to dist/thumbnailator-5.0.11.xar index a6eee8e..fad996b 100644 Binary files a/dist/thumbnailator-4.1.5.xar and b/dist/thumbnailator-5.0.11.xar differ diff --git a/doc/constrain/A17057.jpg b/doc/constrain/A17057.jpg new file mode 100644 index 0000000..04a9630 Binary files /dev/null and b/doc/constrain/A17057.jpg differ diff --git a/doc/constrain/constrain.xq b/doc/constrain/constrain.xq new file mode 100644 index 0000000..64c7d2e --- /dev/null +++ b/doc/constrain/constrain.xq @@ -0,0 +1,29 @@ +(:~ + :examples of constrain use +:) +import module namespace t="expkg-zone58:image.thumbnailator"; +declare variable $file-base:=file:parent(static-base-uri()); + +declare variable $src:=file:resolve-path("A17057.jpg",$file-base); +declare function local:wi($data as xs:base64Binary,$filename as xs:string) +{ + file:write-binary(file:resolve-path($filename,$file-base),$data) +}; +declare function local:constrain($aspect as xs:boolean,$fit as xs:boolean,$exif as xs:boolean) +{ + + + + +}; +let $s:=function($b){if($b) then ".+" else ".-"} +let $img:= fetch:binary($src) +let $ft:=(false(),true()) +for $fit in $ft,$aspect in $ft,$exif in $ft +let $file:=("out.", + $s($aspect) , "aspect", + $s($fit), "fit", + $s($exif), "exif", + ".jpg")=>string-join("") +let $task:=local:constrain($aspect,$fit,$exif) +return t:task($img,$task) => local:wi($file) diff --git a/doc/constrain/out..+aspect.+fit.+exif.jpg b/doc/constrain/out..+aspect.+fit.+exif.jpg new file mode 100644 index 0000000..8d6cfe3 Binary files /dev/null and b/doc/constrain/out..+aspect.+fit.+exif.jpg differ diff --git a/doc/constrain/out..+aspect.+fit.-exif.jpg b/doc/constrain/out..+aspect.+fit.-exif.jpg new file mode 100644 index 0000000..8d6cfe3 Binary files /dev/null and b/doc/constrain/out..+aspect.+fit.-exif.jpg differ diff --git a/doc/constrain/out..+aspect.-fit.+exif.jpg b/doc/constrain/out..+aspect.-fit.+exif.jpg new file mode 100644 index 0000000..d9b9ac3 Binary files /dev/null and b/doc/constrain/out..+aspect.-fit.+exif.jpg differ diff --git a/doc/constrain/out..+aspect.-fit.-exif.jpg b/doc/constrain/out..+aspect.-fit.-exif.jpg new file mode 100644 index 0000000..d9b9ac3 Binary files /dev/null and b/doc/constrain/out..+aspect.-fit.-exif.jpg differ diff --git a/doc/constrain/out..-aspect.+fit.+exif.jpg b/doc/constrain/out..-aspect.+fit.+exif.jpg new file mode 100644 index 0000000..485cb39 Binary files /dev/null and b/doc/constrain/out..-aspect.+fit.+exif.jpg differ diff --git a/doc/constrain/out..-aspect.+fit.-exif.jpg b/doc/constrain/out..-aspect.+fit.-exif.jpg new file mode 100644 index 0000000..485cb39 Binary files /dev/null and b/doc/constrain/out..-aspect.+fit.-exif.jpg differ diff --git a/doc/constrain/out..-aspect.-fit.+exif.jpg b/doc/constrain/out..-aspect.-fit.+exif.jpg new file mode 100644 index 0000000..485cb39 Binary files /dev/null and b/doc/constrain/out..-aspect.-fit.+exif.jpg differ diff --git a/doc/constrain/out..-aspect.-fit.-exif.jpg b/doc/constrain/out..-aspect.-fit.-exif.jpg new file mode 100644 index 0000000..485cb39 Binary files /dev/null and b/doc/constrain/out..-aspect.-fit.-exif.jpg differ diff --git a/doc/filters-schema.png b/doc/filters-schema.png new file mode 100644 index 0000000..fae89ed Binary files /dev/null and b/doc/filters-schema.png differ diff --git a/doc/readme.md b/doc/readme.md new file mode 100644 index 0000000..e2e9010 --- /dev/null +++ b/doc/readme.md @@ -0,0 +1,32 @@ +# expkg-zone58:image.thumbnailator + +The schema is [task.xsd](../src/main/content/task.xsd) + +## thumbnail node + +![root](thumbnail-schema.png "thumbnail node") + +Either `size` or `scale` must be specified. Everything else is optional + +`output` can be used to change the output image format. + +``` + +``` + +## Filters + +![filter definition](filters-schema.png "Available filters") + +## Exif +Image handling is effected by the presence of the +[exif-orientation](http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/) tag. +In particular: +* `size` and `fit` are changed +* the `flip` filter is ignored + +To prevent this set constrain @exif=false + +``` + +``` diff --git a/doc/thumbnail-schema.png b/doc/thumbnail-schema.png new file mode 100644 index 0000000..9dc7820 Binary files /dev/null and b/doc/thumbnail-schema.png differ diff --git a/makejar.jardesc b/makejar.jardesc index ae298e4..76b73bd 100644 --- a/makejar.jardesc +++ b/makejar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/package.xml b/package.xml index a74f806..904a132 100644 --- a/package.xml +++ b/package.xml @@ -16,5 +16,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/readme.md b/readme.md index 8553bfb..4d47693 100644 --- a/readme.md +++ b/readme.md @@ -1,20 +1,31 @@ -# expkg-zone58.image.thumbnailator -An XQuery interface to the thumbnail generator library -[thumbnailator](https://github.com/coobird/thumbnailator). +# expkg-zone58:image.thumbnailator +An XQuery interface to the image thumbnail generator library +[thumbnailator](https://github.com/coobird/thumbnailator) for BaseX 8.6.2+. -Tested against BaseX 8.6.2 +Features size, scale, caption, rotate, flip, colorize, watermark. More details at [doc](doc/readme.md) ## Usage +Images are input and output as `xs:base64Binary` items. Inputs typically come from `fetch:binary` +which allows for file and http sources. Outputs may be saved with `file:write-binary` or `db:store` + ### Simple +Create a thumbnail of given size ```xquery import module namespace t="expkg-zone58:image.thumbnailator"; fetch:binary("http://images.metmuseum.org/CRDImages/ep/original/DT46.jpg") -=>t:size(80,60) +=>t:size(80) +``` +or scale to a fraction of the original +```xquery +import module namespace t="expkg-zone58:image.thumbnailator"; + +fetch:binary("file:///Z:/recordings/radio/Book%20of%20the%20Week/image.png") +=>t:scale(0.25) ``` ### Tasks @@ -39,20 +50,19 @@ let $task:= return fetch:binary("http://images.metmuseum.org/CRDImages/ep/original/DT46.jpg") =>t:task($task) ``` -A schema for this is [provided](./src/main/content/task.xsd) +The schema for this XML is available at [task.xsd](./src/main/content/task.xsd) ## Installation The library is packaged in the [EXpath](http://expath.org/spec/pkg) xar format with -the thumbnailator jar included. See releases for installation instructions. +the thumbnailator jar included. See [releases](../releases) for installation instructions. # Tests `test.xqm` script uses the BaseX [Unit module](http://docs.basex.org/wiki/Unit_Module) ## License -* ex-thumbnailator Copyright (c) 2017, Andy Bunce. (Apache 2 License). +* ex-thumbnailator Copyright (c) 2016-2017, Andy Bunce. (Apache 2 License). * thumbnailator Copyright (c) Chris Kroells (MIT License). -# todo -scale sourceregion \ No newline at end of file + diff --git a/src/java/org/expkgzone58/image/Thumbs.java b/src/java/org/expkgzone58/image/Thumbs.java index 7dbdf02..6595e7c 100644 --- a/src/java/org/expkgzone58/image/Thumbs.java +++ b/src/java/org/expkgzone58/image/Thumbs.java @@ -31,10 +31,10 @@ import net.coobird.thumbnailator.builders.ThumbnailParameterBuilder; import net.coobird.thumbnailator.filters.Pipeline; import net.coobird.thumbnailator.filters.Rotation; import net.coobird.thumbnailator.filters.Watermark; +import net.coobird.thumbnailator.geometry.AbsoluteSize; import net.coobird.thumbnailator.geometry.Position; import net.coobird.thumbnailator.geometry.Positions; import net.coobird.thumbnailator.geometry.Region; -import net.coobird.thumbnailator.geometry.Size; import net.coobird.thumbnailator.tasks.StreamThumbnailTask; import net.coobird.thumbnailator.filters.Canvas; import net.coobird.thumbnailator.filters.Caption; @@ -51,18 +51,18 @@ import net.coobird.thumbnailator.filters.ImageFilter; */ public class Thumbs extends QueryModule{ - public static B64Stream size(final B64Stream inputStream, final int width, final int height) + public B64Stream size(final B64Stream inputStream, final int width, final int height) throws IOException, QueryException { ByteArrayInputStream is = new ByteArrayInputStream(inputStream.binary(null)); ByteArrayOutputStream os = new ByteArrayOutputStream(); ThumbnailParameterBuilder builder = new ThumbnailParameterBuilder(); - builder.size(new Dimension(width, height)); + builder.size(width, height); StreamThumbnailTask task = new StreamThumbnailTask(builder.build(), is, os); Thumbnailator.createThumbnail(task); return new B64Stream(new IOContent(os.toByteArray()), IOERR_X); } - public static B64Stream scale(final B64Stream inputStream, + public B64Stream scale(final B64Stream inputStream, final double xscale, final double yscale) throws IOException, QueryException { ByteArrayInputStream is = new ByteArrayInputStream(inputStream.binary(null)); @@ -74,7 +74,7 @@ public class Thumbs extends QueryModule{ return new B64Stream(new IOContent(os.toByteArray()), IOERR_X); } - public static B64Stream task(final B64Stream inputStream, final ANode thumbnail) + public B64Stream task(final B64Stream inputStream, final ANode thumbnail) throws IOException, QueryException { ByteArrayInputStream is = new ByteArrayInputStream(inputStream.binary(null)); ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -85,13 +85,15 @@ public class Thumbs extends QueryModule{ } // build parameters from XML - static ThumbnailParameter fromNode(final ANode node) throws QueryException, IOException { + ThumbnailParameter fromNode(final ANode node) throws QueryException, IOException { ThumbnailParameterBuilder builder = new ThumbnailParameterBuilder(); + Iterator itr = node.children().iterator(); while (itr.hasNext()) { ANode element = itr.next(); if (element.kind() == Data.ELEM) { String name = Token.string(element.name()); + // FnTrace.trace(name.getBytes(), "element: ".getBytes(), queryContext); switch (name) { case "size": @@ -106,8 +108,8 @@ public class Thumbs extends QueryModule{ region(builder, element); break; - case "exif-orientation": - exif(builder, element); + case "constrain": + constrain(builder, element); break; case "filters": @@ -115,6 +117,12 @@ public class Thumbs extends QueryModule{ builder.filters(filters); break; + case "output": + String format = Utils.attrib(element, "format", + ThumbnailParameter.ORIGINAL_FORMAT); + builder.format(format); + + break; default: break; } @@ -123,37 +131,45 @@ public class Thumbs extends QueryModule{ return builder.build(); } - static void region(final ThumbnailParameterBuilder builder, final ANode node) + void region(final ThumbnailParameterBuilder builder, final ANode node) throws QueryException { int width = (int) Int.parse(node.attribute("width"), null); int height = (int) Int.parse(node.attribute("height"), null); Dimension d = new Dimension(width, height); Position pos = Utils.position(node, "position", Positions.CENTER); - Region r = new Region(pos, (Size) d); + Region r = new Region(pos, new AbsoluteSize(d)); builder.region(r); } - static void exif(final ThumbnailParameterBuilder builder, final ANode node) + + void constrain(final ThumbnailParameterBuilder builder, final ANode node) throws QueryException { - boolean use = Utils.attrib(node, "use", true); - builder.useExifOrientation(use); + + boolean aspect = Utils.attrib(node, "aspect", true); + builder.keepAspectRatio(aspect); + // FnTrace.trace(Boolean.toString(aspect).getBytes(), "constrain: ".getBytes(), queryContext); + boolean exif = Utils.attrib(node, "exif", true); + builder.useExifOrientation(exif); + + boolean fit = Utils.attrib(node, "fit", true); + builder.fitWithinDimensions(fit); } - static void size(final ThumbnailParameterBuilder builder, final ANode node) + void size(final ThumbnailParameterBuilder builder, final ANode node) throws QueryException { int width = (int) Int.parse(node.attribute("width"), null); int height = (int) Int.parse(node.attribute("height"), null); builder.size(width, height); } - static void scale(final ThumbnailParameterBuilder builder, final ANode node) + void scale(final ThumbnailParameterBuilder builder, final ANode node) throws QueryException { double x = Utils.attrib(node, "x", 0.5f); double y = Utils.attrib(node, "y", 0.5f); builder.scale(x, y); } - static List filters(final ANode filters) throws QueryException, IOException { + List filters(final ANode filters) throws QueryException, IOException { Pipeline pipeline = new Pipeline(); Iterator itr = filters.children().iterator(); while (itr.hasNext()) { @@ -193,7 +209,7 @@ public class Thumbs extends QueryModule{ return pipeline.getFilters(); } - private static void watermark(final Pipeline pipeline, final ANode node) + private void watermark(final Pipeline pipeline, final ANode node) throws IOException, QueryException { ImageFilter filter; Position pos; @@ -204,13 +220,13 @@ public class Thumbs extends QueryModule{ pipeline.add(filter); } - private static void rotate(final Pipeline pipeline, final ANode node) + private void rotate(final Pipeline pipeline, final ANode node) throws QueryException { double angle = (double) Dbl.parse(node.attribute("angle"), null); pipeline.add(Rotation.newRotator(angle)); } - private static void flip(final Pipeline pipeline, final ANode node) { + private void flip(final Pipeline pipeline, final ANode node) { ImageFilter filter; String axis = Token.string(node.attribute("axis")); // FnTrace.trace(axis.getBytes(), "FLIP: ".getBytes(), queryContext); @@ -218,7 +234,7 @@ public class Thumbs extends QueryModule{ pipeline.add(filter); } - private static void colorize(final Pipeline pipeline, final ANode node) throws QueryException { + private void colorize(final Pipeline pipeline, final ANode node) throws QueryException { ImageFilter filter; String color; color = Utils.attrib(node, "color", "black"); @@ -227,7 +243,7 @@ public class Thumbs extends QueryModule{ pipeline.add(filter); } - private static void canvas(final Pipeline pipeline, final ANode node) throws QueryException { + private void canvas(final Pipeline pipeline, final ANode node) throws QueryException { ImageFilter filter; String color; Position pos; @@ -239,7 +255,7 @@ public class Thumbs extends QueryModule{ pipeline.add(filter); } - private static void caption(final Pipeline pipeline, final ANode node) throws QueryException { + private void caption(final Pipeline pipeline, final ANode node) throws QueryException { ImageFilter filter; String color; Position pos; @@ -248,9 +264,10 @@ public class Thumbs extends QueryModule{ pos = Utils.position(node, "position", Positions.TOP_CENTER); String fontName = Utils.attrib(node, "font", "SansSerif"); int size = Utils.attrib(node, "size", 14); + int insets = Utils.attrib(node, "insets", 0); Font font = new Font(fontName, Font.PLAIN, size); filter = new Caption(text, font , Utils.stringToColor(color), - pos, 0); + pos, insets); pipeline.add(filter); } } diff --git a/src/main/basex.xml b/src/main/basex.xml index 6ac51ff..008a15b 100644 --- a/src/main/basex.xml +++ b/src/main/basex.xml @@ -1,5 +1,5 @@ - thumbhelper-0.4.17.jar + thumbhelper-5.0.11.jar thumbnailator-0.4.8.jar org.expkgzone58.image.Thumbs diff --git a/src/main/content/task.xsd b/src/main/content/task.xsd index c84e434..895464f 100644 --- a/src/main/content/task.xsd +++ b/src/main/content/task.xsd @@ -2,6 +2,9 @@ + + Root container + @@ -9,42 +12,54 @@ - + + + + size of thumbnail to create + - - + + + + scale thumbnail from source size + - - + + - - - - - - - - - + + + region of source image to use for thumbnail. + default all + + - + + + + + + + contain for filters to be applied to thumbnail + + @@ -58,56 +73,84 @@ + + create a filled enclosing background for thumbnail + + - - - + + + + + tint thumbnail + - - + + + + add text to thumbnail + - + + + + + flip thumbnail horizontally or vertically. + **Ignored if exif-orientation is true ** + + + + rotate the thumbnail + - + + + Add image to thumbnail as a watermark + + - + + + Axis of flip + @@ -115,6 +158,9 @@ + + Region of image to use + @@ -130,4 +176,87 @@ + + + A size in pixels + + + + + + + + + + + + + + + Transparency alpha value + + + + + + + + + + constraints on thumbnail + + + + + true if the Exif metadata should be used to + determine the orientation of the thumbnail, + false otherwise. + + + + + + + fit - true if the thumbnail should be sized to + fit within the specified dimensions, + if the thumbnail is going to + exceed those dimensions. + + + + + + + keep aspect ratio + + + + + + + + Java colour name e.g. "red" + or Color.decode(value) + decimal, octal, or hexidecimal integer e.g + "#FF0096" + + + + + + + + Serialization details for output + + + + + Output image format (JPEG, PNG, GIF, BMP and + WBMP). defaults to source format + + + + \ No newline at end of file diff --git a/src/main/content/thumbhelper-0.4.17.jar b/src/main/content/thumbhelper-0.4.17.jar deleted file mode 100644 index 9024a2c..0000000 Binary files a/src/main/content/thumbhelper-0.4.17.jar and /dev/null differ diff --git a/src/main/content/thumbhelper-5.0.11.jar b/src/main/content/thumbhelper-5.0.11.jar new file mode 100644 index 0000000..a7e9ecd Binary files /dev/null and b/src/main/content/thumbhelper-5.0.11.jar differ diff --git a/src/main/content/thumbnailator.xqm b/src/main/content/thumbnailator.xqm index 073c8b0..61335e1 100644 --- a/src/main/content/thumbnailator.xqm +++ b/src/main/content/thumbnailator.xqm @@ -2,48 +2,83 @@ xquery version "3.1" encoding "UTF-8"; (:~ Generate image thumbnails using the thumbnailator library. : @see https://github.com/coobird/thumbnailator : @author andy bunce - : @version 4.4.1 + : @version 0.5 :) module namespace thumbnails = 'expkg-zone58:image.thumbnailator'; +import module namespace Thumbs = "org.expkgzone58.image.Thumbs"; +(:~ + : generate scaled version of source image with maximum dimension of size + : @param $source base64Binary (streamed?) e.g from `fetch:binary` + : @return base64Binary for thumbnail + :) +declare function thumbnails:size($source as xs:base64Binary,$size as xs:integer) +as xs:base64Binary +{ + Thumbs:size($source,xs:int($size),xs:int($size)) +}; (:~ : generate scaled version of source image with maximum dimension of size : @param $source base64Binary (streamed?) e.g from `fetch:binary` - : @result base64Binary for thumbnail + : @return base64Binary for thumbnail :) declare function thumbnails:size($source as xs:base64Binary,$width as xs:integer,$height as xs:integer) as xs:base64Binary { - Q{java:org.expkgzone58.image.Thumbs}size($source,xs:int($width),xs:int($height)) + Thumbs:size($source,xs:int($width),xs:int($height)) }; (:~ : generate scaled version of source image at given factors 0-1 : @param $source base64Binary (streamed?) e.g from `fetch:binary` - : @result base64Binary for thumbnail + : @return the thumbnail :) -declare function thumbnails:scale($source as xs:base64Binary,$xscale as xs:float,$yscale as xs:float) +declare function thumbnails:scale($source as xs:base64Binary,$scale as xs:double) as xs:base64Binary { - Q{java:org.expkgzone58.image.Thumbs}scale($source,$xscale,$yscale) + Thumbs:scale($source,$scale,$scale) }; +(:~ + : generate scaled version of source image at given factors 0-1 + : @param $source base64Binary (streamed?) e.g from `fetch:binary` + : @return the thumbnail + :) +declare function thumbnails:scale($source as xs:base64Binary,$xscale as xs:double,$yscale as xs:double) +as xs:base64Binary +{ + Thumbs:scale($source,$xscale,$yscale) +}; (:~ : generate thumbnail using parameters specified via XML : @param $source base64Binary (streamed?) e.g from `fetch:binary` : @param $task XML parameters + abbrev="thumbnailator" version="5.0.11" spec="1.0"> An XQuery interface to thumbnailator the thumbnail generator library. diff --git a/src/test/copy.xq b/src/test/copy.xq new file mode 100644 index 0000000..c1395f8 --- /dev/null +++ b/src/test/copy.xq @@ -0,0 +1,34 @@ +(:~ + :examples of constrain use +:) +import module namespace t="expkg-zone58:image.thumbnailator"; +declare variable $file-base:=file:parent(static-base-uri()); +declare variable $watermark:="C:\Users\andy\git\ex-thumbnailator\src\test\resources\icon.gif"; +declare variable $src:=file:resolve-path("resources/A34283.jpg",$file-base); +declare function local:wi($data as xs:base64Binary,$filename as xs:string) +{ + file:write-binary(file:resolve-path($filename,$file-base),$data) +}; +declare function local:constrain($aspect as xs:boolean,$fit as xs:boolean,$exif as xs:boolean) +{ + +}; +let $s:=function($b){if($b) then ".+" else ".-"} +let $img:= fetch:binary($src) +let $ft:=(false(),true()) +for $fit in $ft,$aspect in $ft,$exif in $ft +let $file:=("out", + $s($aspect) , "aspect", + $s($fit), "fit", + $s($exif), "exif")=>string-join("") +let $task:= + + {local:constrain($aspect,$fit,$exif)} + + + {$file} + + + + +return t:task($img,$task) => local:wi("resources/" || $file || ".gif") diff --git a/src/test/resources/A34283.jpg b/src/test/resources/A34283.jpg new file mode 100644 index 0000000..de8eb2f Binary files /dev/null and b/src/test/resources/A34283.jpg differ diff --git a/src/test/resources/icon.gif b/src/test/resources/icon.gif new file mode 100644 index 0000000..09df158 Binary files /dev/null and b/src/test/resources/icon.gif differ diff --git a/src/test/resources/icon.jpg b/src/test/resources/icon.jpg index 9969571..ac80041 100644 Binary files a/src/test/resources/icon.jpg and b/src/test/resources/icon.jpg differ diff --git a/src/test/resources/out.+aspect.+fit.+exif.gif b/src/test/resources/out.+aspect.+fit.+exif.gif new file mode 100644 index 0000000..a499310 Binary files /dev/null and b/src/test/resources/out.+aspect.+fit.+exif.gif differ diff --git a/src/test/resources/out.+aspect.+fit.-exif.gif b/src/test/resources/out.+aspect.+fit.-exif.gif new file mode 100644 index 0000000..f41cd2e Binary files /dev/null and b/src/test/resources/out.+aspect.+fit.-exif.gif differ diff --git a/src/test/resources/out.+aspect.-fit.+exif.gif b/src/test/resources/out.+aspect.-fit.+exif.gif new file mode 100644 index 0000000..3165c16 Binary files /dev/null and b/src/test/resources/out.+aspect.-fit.+exif.gif differ diff --git a/src/test/resources/out.+aspect.-fit.-exif.gif b/src/test/resources/out.+aspect.-fit.-exif.gif new file mode 100644 index 0000000..5f86573 Binary files /dev/null and b/src/test/resources/out.+aspect.-fit.-exif.gif differ diff --git a/src/test/resources/out.-aspect.+fit.+exif.gif b/src/test/resources/out.-aspect.+fit.+exif.gif new file mode 100644 index 0000000..9fa2604 Binary files /dev/null and b/src/test/resources/out.-aspect.+fit.+exif.gif differ diff --git a/src/test/resources/out.-aspect.+fit.-exif.gif b/src/test/resources/out.-aspect.+fit.-exif.gif new file mode 100644 index 0000000..a3b4211 Binary files /dev/null and b/src/test/resources/out.-aspect.+fit.-exif.gif differ diff --git a/src/test/resources/out.-aspect.-fit.+exif.gif b/src/test/resources/out.-aspect.-fit.+exif.gif new file mode 100644 index 0000000..a99cd4a Binary files /dev/null and b/src/test/resources/out.-aspect.-fit.+exif.gif differ diff --git a/src/test/resources/out.-aspect.-fit.-exif.gif b/src/test/resources/out.-aspect.-fit.-exif.gif new file mode 100644 index 0000000..b00fdb2 Binary files /dev/null and b/src/test/resources/out.-aspect.-fit.-exif.gif differ diff --git a/src/test/resources/result2.jpg b/src/test/resources/result2.jpg index cae9091..9d42294 100644 Binary files a/src/test/resources/result2.jpg and b/src/test/resources/result2.jpg differ diff --git a/src/test/rotate.xml b/src/test/rotate.xml index c7ed601..fd386d6 100644 --- a/src/test/rotate.xml +++ b/src/test/rotate.xml @@ -1,6 +1,7 @@ + diff --git a/src/test/sample.xq b/src/test/sample.xq index 9671d35..3186cf7 100644 --- a/src/test/sample.xq +++ b/src/test/sample.xq @@ -12,11 +12,11 @@ let $task:= - + (: let $task:=doc("rotate.xml")/task :) let $x:=fetch:binary($remote) - let $r:=Q{java:org.expkgzone58.image.Thumbs}size($x,xs:int(40),xs:int(40)) + let $r:=t:task($x,$task) (: let $r:=Q{java:org.expkgzone58.image.Thumbs}task($x,$task) :) return file:write-binary($picr,$r) \ No newline at end of file