Skip to content

Commit

Permalink
Added parameter to image reader to allow the prevention of image enla…
Browse files Browse the repository at this point in the history
…rging (whilst still allowing image size reduction)

Updated docs to include this change
Moved image reader from scratchpad to core in book.xml


git-svn-id: https://svn.apache.org/repos/asf/cocoon/trunk@24904 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Upayavira committed Jul 3, 2003
1 parent 2685be0 commit 86baefe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/documentation/xdocs/userdocs/readers/book.xml
Expand Up @@ -12,6 +12,7 @@
<menu-item label="Resource Reader" href="resource-reader.html"/>
</menu>
<menu label="Core">
<menu-item label="Image Reader" href="image-reader.html"/>
</menu>
<menu label="Optional">
<menu-item label="Database Reader" href="database-reader.html"/>
Expand All @@ -21,7 +22,6 @@
<menu-item label="AxisRPC Reader" href="axisrpc-reader.html"/>
<menu-item label="Byte Range Resource Reader" href="byterangeresource-reader.html"/>
<menu-item label="Directory ZIP Archiver" href="directoryziparchiver-reader.html"/>
<menu-item label="Image Reader" href="image-reader.html"/>
</menu>
</book>

18 changes: 16 additions & 2 deletions src/documentation/xdocs/userdocs/readers/image-reader.xml
Expand Up @@ -8,6 +8,7 @@
<type>Technical document</type>
<authors>
<person name="Bernhard Huber" email="huber@apache.org"/>
<person name="Upayavira" email="upayavira@apache.org"/>
</authors>
<abstract>This document describes the ImageReader of Cocoon.</abstract>
</header>
Expand Down Expand Up @@ -112,18 +113,29 @@
<td>
This parameter is optional. When specified it determines the width
of the binary image.
If no height parameter is specified the ascpect ratio
If no height parameter is specified the aspect ratio
of the image is kept.
</td>
</tr>
<tr><td>height</td><td>Image height in pixels</td>
<td>
This parameter is optional. When specified it determines the width
of the binary image.
If no width parameter is specified the ascpect ratio
If no width parameter is specified the aspect ratio
of the image is kept.
</td>
</tr>
<tr><td>allow-enlarging</td><td>Allow or prevent the enlarging of images</td>
<td>
This parameter is optional. The <code>width</code> and <code>height</code> parameters allow an image
to be resized. By default, if the image is smaller than the specified
width and height, the image will be enlarged. In some circumstances, this
behaviour is undesirable, and can be switched off by setting this parameter
to <code>no</code>. With this parameter set to <code>no</code>, images will
be reduced in size, but not enlarged. The default for this parameter is
<code>yes</code>.
</td>
</tr>
</table>
<p>
The following pipeline snippet
Expand Down Expand Up @@ -170,6 +182,8 @@
<br/>
01-06-03: Renamed the expire-time -> expires parameter,
Fixed the statement about the byte range support, Torsten Curdt
<br/>
03-07-03: Added allow-enlarging parameter, Upayavira
</p>
</s1>
<s1 title="Copyright">
Expand Down
23 changes: 21 additions & 2 deletions src/java/org/apache/cocoon/reading/ImageReader.java
Expand Up @@ -92,12 +92,14 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
* @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
* @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
* @version CVS $Id: ImageReader.java,v 1.1 2003/06/27 20:10:43 stefano Exp $
* @version CVS $Id: ImageReader.java,v 1.2 2003/07/03 09:43:25 upayavira Exp $
*/
final public class ImageReader extends ResourceReader {

private int width;
private int height;
private boolean enlarge;
private final static String ENLARGE_DEFAULT = "true";

public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
throws ProcessingException, SAXException, IOException {
Expand All @@ -106,6 +108,13 @@ public void setup(SourceResolver resolver, Map objectModel, String src, Paramete

width = par.getParameterAsInteger("width", 0);
height = par.getParameterAsInteger("height", 0);

String enlargePar = par.getParameter("allow-enlarging", ENLARGE_DEFAULT);
if ("true".equalsIgnoreCase(enlargePar) || "yes".equalsIgnoreCase(enlargePar)){
enlarge = true;
} else {
enlarge = false;
}
}

/**
Expand Down Expand Up @@ -137,9 +146,19 @@ private AffineTransform getTransform(double ow, double oh, double nw, double nh)
}
}

if (!enlarge) {
if ((nw > ow && nh <= 0) || (oh > nh && nw <=0)) {
wm = 1.0d;
hm = 1.0d;
} else if (nw > ow) {
wm = 1.0d;
} else if (nh > oh) {
hm = 1.0d;
}
}
return new AffineTransform(wm, 0.0d, 0.0d, hm, 0.0d, 0.0d);
}

protected void processStream() throws IOException, ProcessingException {
if (width > 0 || height > 0) {
if (getLogger().isDebugEnabled()) {
Expand Down

0 comments on commit 86baefe

Please sign in to comment.