basex v9 stream->lazy

This commit is contained in:
Andy Bunce 2017-11-24 23:48:45 +00:00
parent 1e74f304f3
commit 9294164247
15 changed files with 65 additions and 21 deletions

View File

@ -1,12 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Program Files (x86)/BaseX/BaseX.jar" sourcepath="/basex-core/src"/>
<classpathentry kind="lib" path="src/main/content/thumbnailator-0.4.8.jar"/>
<classpathentry kind="lib" path="lib/BaseX90-20171123.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

View File

@ -1,6 +1,6 @@
<xqdoc:xqdoc xmlns:xqdoc="http://www.xqdoc.org/1.0">
<xqdoc:control>
<xqdoc:date>2017-04-29T22:28:45.705+01:00</xqdoc:date>
<xqdoc:date>2017-11-24T23:26:38.524Z</xqdoc:date>
<xqdoc:version>1.1</xqdoc:version>
</xqdoc:control>
<xqdoc:module type="library">

BIN
dist/thumbnailator-6.0.2.xar vendored Normal file

Binary file not shown.

BIN
lib/BaseX90-20171123.jar Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
<jardesc>
<jar path="ex-thumbnailator/src/main/content/thumbhelper-5.0.11.jar"/>
<jar path="ex-thumbnailator/src/main/content/thumbhelper-6.0.0.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/ex-thumbnailator/makejar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>

View File

@ -49,5 +49,14 @@
<version num="5.0.11">
<!-- generated: {fn:current-dateTime()} -->
</version>
<version num="6.0.0">
<!-- generated: {fn:current-dateTime()} -->
</version>
<version num="6.0.1">
<!-- generated: {fn:current-dateTime()} -->
</version>
<version num="6.0.2">
<!-- generated: {fn:current-dateTime()} -->
</version>
</pkg>
</repo>

View File

@ -1,9 +1,11 @@
# expkg-zone58:image.thumbnailator
An XQuery interface to the image thumbnail generator library
[thumbnailator](https://github.com/coobird/thumbnailator) for BaseX 8.6.2+.
[thumbnailator](https://github.com/coobird/thumbnailator) for BaseX 9+.
Features size, scale, caption, rotate, flip, colorize, watermark. More details at [doc](doc/readme.md)
## Versions
* For Basex 9+ use thumbnailator 6.0.2+
## Usage
@ -61,7 +63,7 @@ the thumbnailator jar included. See [releases](../../releases) for installation
## License
* ex-thumbnailator Copyright (c) 2016-2017, Andy Bunce. (Apache 2 License).
* ex-thumbnailator Copyright (c) 2013-2017, Andy Bunce. (Apache 2 License).
* thumbnailator Copyright (c) Chris Kroells (MIT License).

View File

@ -18,7 +18,7 @@ import org.basex.io.IOContent;
import org.basex.query.QueryException;
import org.basex.query.QueryModule;
//import org.basex.query.func.fn.FnTrace;
import org.basex.query.value.item.B64Stream;
import org.basex.query.value.item.B64Lazy;
import org.basex.query.value.item.Dbl;
import org.basex.query.value.item.Int;
import org.basex.query.value.node.ANode;
@ -51,7 +51,7 @@ import net.coobird.thumbnailator.filters.ImageFilter;
*/
public class Thumbs extends QueryModule{
public B64Stream size(final B64Stream inputStream, final int width, final int height)
public B64Lazy size(final B64Lazy inputStream, final int width, final int height)
throws IOException, QueryException {
ByteArrayInputStream is = new ByteArrayInputStream(inputStream.binary(null));
ByteArrayOutputStream os = new ByteArrayOutputStream();
@ -59,10 +59,10 @@ public class Thumbs extends QueryModule{
builder.size(width, height);
StreamThumbnailTask task = new StreamThumbnailTask(builder.build(), is, os);
Thumbnailator.createThumbnail(task);
return new B64Stream(new IOContent(os.toByteArray()), IOERR_X);
return new B64Lazy(new IOContent(os.toByteArray()), IOERR_X);
}
public B64Stream scale(final B64Stream inputStream,
public B64Lazy scale(final B64Lazy inputStream,
final double xscale, final double yscale)
throws IOException, QueryException {
ByteArrayInputStream is = new ByteArrayInputStream(inputStream.binary(null));
@ -71,17 +71,17 @@ public class Thumbs extends QueryModule{
builder.scale(xscale, yscale);
StreamThumbnailTask task = new StreamThumbnailTask(builder.build(), is, os);
Thumbnailator.createThumbnail(task);
return new B64Stream(new IOContent(os.toByteArray()), IOERR_X);
return new B64Lazy(new IOContent(os.toByteArray()), IOERR_X);
}
public B64Stream task(final B64Stream inputStream, final ANode thumbnail)
public B64Lazy task(final B64Lazy inputStream, final ANode thumbnail)
throws IOException, QueryException {
ByteArrayInputStream is = new ByteArrayInputStream(inputStream.binary(null));
ByteArrayOutputStream os = new ByteArrayOutputStream();
ThumbnailParameter param = fromNode(thumbnail);
StreamThumbnailTask task = new StreamThumbnailTask(param, is, os);
Thumbnailator.createThumbnail(task);
return new B64Stream(new IOContent(os.toByteArray()), IOERR_X);
return new B64Lazy(new IOContent(os.toByteArray()), IOERR_X);
}
// build parameters from XML

View File

@ -1,5 +1,5 @@
<package xmlns="http://www.basex.org/modules/pkg">
<jar>thumbhelper-5.0.11.jar</jar>
<jar>thumbhelper-6.0.0.jar</jar>
<jar>thumbnailator-0.4.8.jar</jar>
<class>org.expkgzone58.image.Thumbs</class>
</package>

Binary file not shown.

View File

@ -1,8 +1,8 @@
<package xmlns="http://expath.org/ns/pkg" name="https://github.com/expkg-zone58/ex-thumbnailator"
abbrev="thumbnailator" version="5.0.11" spec="1.0">
abbrev="thumbnailator" version="6.0.2" spec="1.0">
<title>An XQuery interface to thumbnailator the thumbnail generator library.</title>
<dependency processor="basex" />
<xquery>
<namespace>expkg-zone58:image.thumbnailator</namespace>
<file>thumbnailator.xqm</file>

37
src/test/inset.xq Normal file
View File

@ -0,0 +1,37 @@
(:~
:examples of inset use
:)
import module namespace t="expkg-zone58:image.thumbnailator";
declare variable $watermark:=local:path("resources\icon.gif");
declare variable $src:=local:path("resources/A34283.jpg");
declare function local:path($name){
file:resolve-path($name,file:base-dir())
};
declare function local:save($data as xs:base64Binary,$filename as xs:string)
{
file:write-binary(local:path($filename),$data)
};
let $img:= fetch:binary($src)
let $task:=<thumbnail>
<size width="300" height="300"/>
<constrain fit="true"/>
<filters>
<rotate angle="45"/>
<caption size="60" color="white" position="CENTER">DRAFT</caption>
<rotate angle="-45"/>
<canvas height="300" width="300" color="lightGray" position="CENTER"/>
<caption size="30" color="black" insets="10"
position="TOP_CENTER">Caption insets = 10</caption>
<watermark src="{$watermark}" alpha="1" position="BOTTOM_RIGHT"/>
<caption size="30" color="black" insets="-3"
position="BOTTOM_LEFT">BOTTOM_LEFT -3</caption>
</filters>
<output format="gif"/>
</thumbnail>
return t:task($img,$task) => local:save("resources/" || "inset.gif")

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -32,7 +32,7 @@ declare %updating function write-xqdoc($path,$src,$dest){
case "application/xquery"
return file:write(
fn:resolve-uri($path || ".xml",$dest),
inspect:xqdoc($url)
inspect:xqdoc($url)
)
default
return ()