update to thumbnailator 0.4.8

This commit is contained in:
Andy Bunce 2016-04-16 22:21:17 +01:00
parent b91d5adfcb
commit 4b00a768fa
18 changed files with 303 additions and 98 deletions

11
.project Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ex-thumbnailator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

12
LICENSE
View file

@ -176,18 +176,8 @@
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following Copyright 2016 andy bunce
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2013 andy bunce
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View file

@ -1,16 +0,0 @@
(: create o/ps
: xar package and xqdoc
:)
declare function local:read($item){
let $f:=fn:resolve-uri($item/@src)
return file:read-binary($f)
};
let $pack:=doc(resolve-uri("package.xml"))/*
let $files:=$pack/*
let $zip := archive:create( $files/@dest/fn:string(), $files ! local:read(.))
return ( file:write-binary(resolve-uri($pack/@dest),$zip)
,file:write(resolve-uri("dist/xqdoc.xml"),inspect:xqdoc(resolve-uri("src/main/content/thumbnailator.xqm")))
)

96
dist/doc/thumbnailator.xqm.xml vendored Normal file
View file

@ -0,0 +1,96 @@
<xqdoc:xqdoc xmlns:xqdoc="http://www.xqdoc.org/1.0">
<xqdoc:control>
<xqdoc:date>2016-04-16T22:19:53.356+01:00</xqdoc:date>
<xqdoc:version>1.1</xqdoc:version>
</xqdoc:control>
<xqdoc:module type="library">
<xqdoc:uri>expkg-zone58.image.thumbnailator</xqdoc:uri>
<xqdoc:name>thumbnailator.xqm</xqdoc:name>
<xqdoc:comment>
<xqdoc:description>Generate thumbnails using http://code.google.com/p/thumbnailator/</xqdoc:description>
<xqdoc:author>andy bunce</xqdoc:author>
</xqdoc:comment>
</xqdoc:module>
<xqdoc:namespaces>
<xqdoc:namespace prefix="thumbnails" uri="expkg-zone58.image.thumbnailator"/>
<xqdoc:namespace prefix="File" uri="java:java.io.File"/>
<xqdoc:namespace prefix="Thumbnailator" uri="java:net.coobird.thumbnailator.Thumbnailator"/>
<xqdoc:namespace prefix="BufferedImageBuilder" uri="java:net.coobird.thumbnailator.builders.BufferedImageBuilder"/>
<xqdoc:namespace prefix="Builder" uri="java:net.coobird.thumbnailator.Thumbnails$Builder"/>
</xqdoc:namespaces>
<xqdoc:imports/>
<xqdoc:variables/>
<xqdoc:functions>
<xqdoc:function arity="4">
<xqdoc:name>sourceRegion</xqdoc:name>
<xqdoc:signature>declare function sourceRegion($x as xs:integer, $y as xs:integer, $width as xs:integer, $height as xs:integer) as item()*</xqdoc:signature>
<xqdoc:parameters>
<xqdoc:parameter>
<xqdoc:name>x</xqdoc:name>
<xqdoc:type>xs:integer</xqdoc:type>
</xqdoc:parameter>
<xqdoc:parameter>
<xqdoc:name>y</xqdoc:name>
<xqdoc:type>xs:integer</xqdoc:type>
</xqdoc:parameter>
<xqdoc:parameter>
<xqdoc:name>width</xqdoc:name>
<xqdoc:type>xs:integer</xqdoc:type>
</xqdoc:parameter>
<xqdoc:parameter>
<xqdoc:name>height</xqdoc:name>
<xqdoc:type>xs:integer</xqdoc:type>
</xqdoc:parameter>
</xqdoc:parameters>
<xqdoc:return>
<xqdoc:type occurrence="*">item()</xqdoc:type>
</xqdoc:return>
</xqdoc:function>
<xqdoc:function arity="3">
<xqdoc:name>size</xqdoc:name>
<xqdoc:signature>declare function size($builder as item()*, $width as xs:int, $height as xs:int) as item()*</xqdoc:signature>
<xqdoc:parameters>
<xqdoc:parameter>
<xqdoc:name>builder</xqdoc:name>
<xqdoc:type occurrence="*">item()</xqdoc:type>
</xqdoc:parameter>
<xqdoc:parameter>
<xqdoc:name>width</xqdoc:name>
<xqdoc:type>xs:int</xqdoc:type>
</xqdoc:parameter>
<xqdoc:parameter>
<xqdoc:name>height</xqdoc:name>
<xqdoc:type>xs:int</xqdoc:type>
</xqdoc:parameter>
</xqdoc:parameters>
<xqdoc:return>
<xqdoc:type occurrence="*">item()</xqdoc:type>
</xqdoc:return>
</xqdoc:function>
<xqdoc:function arity="4">
<xqdoc:name>create-thumbnail</xqdoc:name>
<xqdoc:signature>declare function create-thumbnail($src as xs:string, $dest as xs:string, $width as xs:integer, $height as xs:integer) as item()*</xqdoc:signature>
<xqdoc:parameters>
<xqdoc:parameter>
<xqdoc:name>src</xqdoc:name>
<xqdoc:type>xs:string</xqdoc:type>
</xqdoc:parameter>
<xqdoc:parameter>
<xqdoc:name>dest</xqdoc:name>
<xqdoc:type>xs:string</xqdoc:type>
</xqdoc:parameter>
<xqdoc:parameter>
<xqdoc:name>width</xqdoc:name>
<xqdoc:type>xs:integer</xqdoc:type>
</xqdoc:parameter>
<xqdoc:parameter>
<xqdoc:name>height</xqdoc:name>
<xqdoc:type>xs:integer</xqdoc:type>
</xqdoc:parameter>
</xqdoc:parameters>
<xqdoc:return>
<xqdoc:type occurrence="*">item()</xqdoc:type>
</xqdoc:return>
</xqdoc:function>
</xqdoc:functions>
</xqdoc:xqdoc>

BIN
dist/thumbnailator.zar vendored

Binary file not shown.

View file

@ -1,6 +1,21 @@
<zip dest="dist/thumbnailator.zar"> <!-- @see http://cxan.org/faq#add-pkg -->
<file src="src/main/expath-pkg.xml" dest="expath-pkg.xml" /> <repo abbrev="ex-thumbnailator">
<file src="src/main/basex.xml" dest="basex.xml" /> <pkg abbrev="ex-thumbnailator" id="expkg-zone58.image.thumbnailator">
<file src="src/main/content/thumbnailator.xqm" dest="content/thumbnailator.xqm" /> <name>expkg-zone58.image.thumbnailator</name>
<file src="src/main/content/thumbnailator-0.4.5.jar" dest="content/thumbnailator-0.4.5.jar" /> <abstract>Create a thumbnail from a file path.</abstract>
</zip> <author id="coobird">coobird</author>
<maintainer id="abunce">Andy Bunce</maintainer>
<home>https://github.com/coobird/thumbnailator</home>
<category id="libs">Library</category>
<tag>image</tag>
<tag>resize</tag>
<tag>graphic</tag>
<version num="2.0.0">
<dependency processor="basex"/>
<file name="ex-dotml-0.0.5.xar" role="pkg"/>
</version>
<version num="2.0.1">
<!-- generated: {fn:current-dateTime()} -->
</version>
</pkg>
</repo>

View file

@ -1,8 +1,8 @@
# apb.image.thumbnailator # expkg-zone58.image.thumbnailator
An XQuery interface to the thumbnail generator library An XQuery interface to the thumbnail generator library
[thumbnailator](http://code.google.com/p/thumbnailator/) [thumbnailator](https://github.com/coobird/thumbnailator)
BaseX 7.7 or greater is required. Tested against BaseX 8.4.3.
# Installation # Installation
@ -10,15 +10,16 @@ The library is packaged in the [EXpath](http://expath.org/spec/pkg) xar format w
the thumbnailator jar included. It can be installed into the BaseX repository by the thumbnailator jar included. It can be installed into the BaseX repository by
executing the command: executing the command:
```` ````
repo:install('http://apb2006.github.io/thumbnailator/dist/thumbnailator.zar') repo:install('https://github.com/expkg-zone58/ex-thumbnailator/dist/thumbnailator.zar')
```` ````
# Usage # Usage
```` ````
import module namespace t="apb.image.thumbnailator"; import module namespace t="expkg-zone58.image.thumbnailator";
t:make("/tmp/pic.jpg","/tmp/small.jpg",120,120) t:create-thumbnail("/tmp/pic.jpg","/tmp/small.jpg",120,120)
```` ````
# Tests # Tests
The `test.xq` script uses the BaseX [Unit module](http://docs.basex.org/wiki/Unit_Module) `test.xqm` script uses the BaseX [Unit module](http://docs.basex.org/wiki/Unit_Module)
todo
# # todo
explore java binding limits and fluent interface explore java binding limits and fluent interface

View file

@ -1,4 +1,4 @@
<package xmlns="http://www.basex.org/modules/pkg"> <package xmlns="http://www.basex.org/modules/pkg">
<jar>thumbnailator-0.4.5.jar</jar> <jar>thumbnailator-0.4.8.jar</jar>
<class>net.coobird.thumbnailator.Thumbnails</class> <class>net.coobird.thumbnailator.Thumbnails</class>
</package> </package>

Binary file not shown.

View file

@ -2,8 +2,8 @@ xquery version "3.0" encoding "UTF-8";
(:~ Generate thumbnails using http://code.google.com/p/thumbnailator/ (:~ Generate thumbnails using http://code.google.com/p/thumbnailator/
: @author andy bunce : @author andy bunce
:) :)
module namespace thumbnails = 'apb.image.thumbnailator'; module namespace thumbnails = 'expkg-zone58.image.thumbnailator';
declare default function namespace 'apb.image.thumbnailator'; declare default function namespace 'expkg-zone58.image.thumbnailator';
declare namespace File="java:java.io.File"; declare namespace File="java:java.io.File";
declare namespace Thumbnailator="java:net.coobird.thumbnailator.Thumbnailator"; declare namespace Thumbnailator="java:net.coobird.thumbnailator.Thumbnailator";
@ -15,10 +15,10 @@ Thumbnails.of(new File("path/to/directory").listFiles())
.outputFormat("jpg") .outputFormat("jpg")
.toFiles(Rename.PREFIX_DOT_THUMBNAIL); .toFiles(Rename.PREFIX_DOT_THUMBNAIL);
:) :)
declare function fromFilenames($file as xs:string){ (: declare function fromFilenames($file as xs:string){
let $a:=File:new(file:path-to-native($file)) let $a:=File:new(file:path-to-native($file))
return Builder:of(($a,$a)) return Builder:of(($a,$a))
}; }; :)
declare function sourceRegion($x as xs:integer,$y as xs:integer, declare function sourceRegion($x as xs:integer,$y as xs:integer,
$width as xs:integer,$height as xs:integer){ $width as xs:integer,$height as xs:integer){
@ -29,11 +29,12 @@ declare function size($builder,$width as xs:int,$height as xs:int){
BufferedImageBuilder:size($builder,$width,$height) BufferedImageBuilder:size($builder,$width,$height)
}; };
declare function make($src as xs:string, declare function create-thumbnail($src as xs:string,
$dest as xs:string, $dest as xs:string,
$width as xs:integer, $width as xs:integer,
$height as xs:integer){ $height as xs:integer){
let $src:=File:new(file:path-to-native($src)) let $src:=File:new(file:resolve-path($src))
let $dest:=File:new(file:path-to-native($dest)) let $dest:=File:new(file:resolve-path($dest))
return Thumbnailator:createThumbnail($src,$dest,xs:int($width),xs:int($height)) return Thumbnailator:createThumbnail($src,$dest,xs:int($width),xs:int($height))
}; };

10
src/main/cxan.xml Normal file
View file

@ -0,0 +1,10 @@
<package xmlns="http://cxan.org/ns/package" id="thumbnailator">
<abstract>Create a thumbnail from a file path. </abstract>
<author id="coobird">coobird</author>
<maintainer id="abunce">Andy Bunce</maintainer>
<home>https://github.com/coobird/thumbnailator</home>
<category id="libs">Library</category>
<tag>image</tag>
<tag>resize</tag>
<tag>graphic</tag>
</package>

View file

@ -1,13 +1,13 @@
<package xmlns="http://expath.org/ns/pkg" <package xmlns="http://expath.org/ns/pkg"
name="apb.image.thumbnailator" name="expkg-zone58.image.thumbnailator"
abbrev="content" abbrev="thumbnailator"
version="1.0.2" version="2.0.1"
spec="1.0"> spec="1.0">
<title>Generate thumbnails using http://code.google.com/p/thumbnailator/</title> <title>Generate thumbnails using http://code.google.com/p/thumbnailator/</title>
<dependency processor="basex" /> <dependency processor="basex" />
<xquery> <xquery>
<namespace>apb.image.thumbnailator</namespace> <namespace>expkg-zone58.image.thumbnailator</namespace>
<file>thumbnailator.xqm</file> <file>thumbnailator.xqm</file>
</xquery> </xquery>

View file

@ -1,43 +0,0 @@
(:~
: unit tests for thumbnail module
:)
import module namespace t="apb.image.thumbnailator" at "../main/content/thumbnailator.xqm";
declare variable $pic1:=resolve-uri("simple.jpg");
declare variable $picr:=resolve-uri("out.jpg");
(:~ Initializing function, which is called once before all tests. :)
declare
%unit:before-module
function local:before-all-tests() { ()
};
(:~ Initializing function, which is called once after all tests. :)
declare
%unit:after-module
function local:after-all-tests() { ()
};
(:~ Initializing function, which is called before each test. :)
declare
%unit:before
function local:before() { ()
};
(:~ Initializing function, which is called after each test. :)
declare
%unit:after
function local:after() { ()
};
(:~ we get tags :)
declare
%unit:test
function local:success-function() {
let $r:=t:make($pic1,$picr,60,60)
return unit:assert(fn:empty($r))
};
(: run all tests :)
unit:test()

21
src/test/test.xqm Normal file
View file

@ -0,0 +1,21 @@
module namespace test = 'http://basex.org/modules/xqunit-tests';
(:~
: unit tests for thumbnail module
:)
import module namespace t="expkg-zone58.image.thumbnailator" at "../main/content/thumbnailator.xqm";
declare namespace File="java:java.io.File";
declare variable $test:pic1:=resolve-uri("simple.jpg");
declare variable $test:picr:=resolve-uri("out.jpg");
(:~ make a thumbnail :)
declare
%unit:test
function test:create-thumbnail() {
let $r:=t:create-thumbnail($test:pic1,$test:picr,60,60)
return unit:assert(fn:empty($r))
};

34
tools/build.xq Normal file
View file

@ -0,0 +1,34 @@
(: create o/ps
: xar package and xqdoc
:)
declare namespace pkg="http://expath.org/ns/pkg";
import module namespace build = "quodatum.utils.build" at "buildx.xqm";
declare variable $base:=resolve-uri("../");
declare variable $src:=resolve-uri("../src/main/");
declare variable $dest:=resolve-uri("../dist/");
(:~
: the package definition as a pkg:package
:)
declare variable $package as element(pkg:package) :=doc(resolve-uri("expath-pkg.xml",$src))/pkg:package;
declare variable $content:=resolve-uri("content/",$src);
declare variable $dest-doc:=resolve-uri("doc/",$dest);
let $files:=build:files($src)
let $name:= build:xar-name($package)
return (
(: save xqdoc :)
build:files($content)!build:write-xqdoc(.,$content,$dest-doc),
(: write xar file :)
file:write-binary(
resolve-uri($name,$dest),
archive:create($files,$files!file:read-binary(fn:resolve-uri(.,$src)))
),
(: update package.xml located at $cxan :)
build:publish($package,resolve-uri("package.xml",$base))
)

66
tools/buildx.xqm Normal file
View file

@ -0,0 +1,66 @@
(:~
: build utils
: @author Andy Bunce
: @copyright Quodatum Ltd
: @licence Apache 2
: @since may-2015
:)
module namespace build = 'quodatum.utils.build';
declare default function namespace 'quodatum.utils.build';
declare namespace pkg="http://expath.org/ns/pkg";
(:~
: file paths below $src
: $src typically from resolve-uri
: @return sequences of relative file paths "content/ebnf/CR-xquery-31-20141218.ebnf" "..."
:)
declare function files($src as xs:string) as xs:string*
{
fn:filter(file:list($src,fn:true()),
function ($f){file:is-file($src || $f)}
)
!fn:translate(.,"\","/")
};
(:~
: write xqdoc for $src/$path to $dest
:)
declare %updating function write-xqdoc($path,$src,$dest){
let $url:=fn:resolve-uri( $path,$src)
let $type:=fetch:content-type($url)
return switch($type)
case "application/xquery"
return file:write(
fn:resolve-uri($path || ".xml",$dest),
inspect:xqdoc($url)
)
default
return ()
};
(:~
: name of dist xar file eg "fred-0.1.0.xar"
:)
declare function xar-name($package as element(pkg:package)) as xs:string
{
fn:concat($package/@abbrev , "-" ,$package/@version, ".xar")
};
(:~
: update package.xml located at $cxan to ensure has entry for package $pkg
:)
declare %updating function publish($pkg as element(pkg:package),$cxan)
{
let $doc:=copy $c:=fn:doc($cxan)
modify(
let $pack:=$c/repo/pkg[name=$pkg/@name]
let $hit:= $pack/version[@num=$pkg/@version]
let $new:=<version num="{$pkg/@version}">
<!-- generated: {fn:current-dateTime()} -->
</version>
return if($hit)then ()
else insert node $new into $pack
)
return $c
return fn:put($doc,$cxan)
};

19
tools/test.xq Normal file
View file

@ -0,0 +1,19 @@
(: create o/ps
: xar package and xqdoc
:)
declare namespace pkg="http://expath.org/ns/pkg";
import module namespace build = "quodatum.utils.build" at "buildx.xqm";
declare variable $base:=resolve-uri("../");
declare variable $src:=resolve-uri("../src/main/");
declare variable $dest:=resolve-uri("../dist/");
(:~
: the package definition as a pkg:package
:)
declare variable $package as element(pkg:package) :=doc(resolve-uri("expath-pkg.xml",$src))/pkg:package;
declare variable $content:=resolve-uri("content/",$src);
declare variable $dest-doc:=resolve-uri("doc/",$dest);
build:files($src)