Skip to content

Commit 96c19b7

Browse files
authored
Merge pull request #68 from robcast/webp-support
Fix webp forced output type.
2 parents 64b9d93 + 712c5d3 commit 96c19b7

File tree

5 files changed

+11
-31
lines changed

5 files changed

+11
-31
lines changed

common/src/main/java/digilib/image/ImageJobDescription.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,10 @@ public boolean isImageSendable() throws IOException {
11341134
// input image is browser compatible
11351135
&& input.hasTag(ImageInput.InputTag.SENDABLE)
11361136
// no forced type conversion
1137+
// TODO: use getOutputMimeType
11371138
&& !(request.hasOption(DigilibOption.jpg) && !mimeType.equals("image/jpeg"))
11381139
&& !(request.hasOption(DigilibOption.png) && !mimeType.equals("image/png"))
1140+
&& !(request.hasOption(DigilibOption.webp) && !mimeType.equals("image/webp"))
11391141
// no zooming
11401142
&& !isZoomRequested()
11411143
// no other image operations

common/src/main/java/digilib/io/FileOps.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public class FileOps {
4848
{ "fpx", "image/fpx" }, { "svg", "image/svg+xml" },
4949
{ "txt", "text/plain" }, { "html", "text/html" },
5050
{ "htm", "text/html" }, { "xml", "text/xml" },
51-
{ "meta", "text/xml" }, { "json", "application/json" }
51+
{ "meta", "text/xml" }, { "json", "application/json" },
52+
{ "webp", "image/webp" }
5253
};
5354

5455
public static Map<String, String> fileTypes;

servlet/src/main/java/digilib/servlet/ServletOps.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,9 @@ public static void sendImage(DocuImage img, String mimeType, HttpServletResponse
313313
return;
314314
}
315315
try {
316-
/*
317-
* determine the content-type: if mime type is set use that otherwise if source
318-
* is JPG then dest will be JPG else it's PNG
319-
*/
320316
if (mimeType == null) {
321-
mimeType = img.getMimetype();
322-
if (mimeType == null) {
323-
// still no mime-type
324-
logger.warn("sendImage without mime-type! using image/jpeg.");
325-
mimeType = "image/jpeg";
326-
}
327-
}
328-
if ((mimeType.equals("image/jpeg") || mimeType.equals("image/jp2") || mimeType.equals("image/fpx"))) {
317+
logger.warn("sendImage without mime-type! using image/jpeg.");
329318
mimeType = "image/jpeg";
330-
} else {
331-
mimeType = "image/png";
332319
}
333320
// set the content type
334321
response.setContentType(mimeType);

servlet2/src/main/java/digilib/servlet/Scaler.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,8 @@ public void processRequest(HttpServletRequest request, HttpServletResponse respo
291291
Future<DocuImage> jobResult = imageJobCenter.submit(job);
292292
// wait for result
293293
DocuImage img = jobResult.get();
294-
// forced destination image type
295-
String mt = null;
296-
if (jobTicket.getRequest().hasOption(DigilibOption.jpg)) {
297-
mt = "image/jpeg";
298-
} else if (jobTicket.getRequest().hasOption(DigilibOption.png)) {
299-
mt = "image/png";
300-
}
294+
// get destination image type
295+
String mt = jobTicket.getOutputMimeType();
301296
// send image
302297
ServletOps.sendImage(img, mt, response, logger);
303298
logger.debug("Job Processing Time: " + (System.currentTimeMillis() - startTime) + "ms");

servlet3/src/main/java/digilib/servlet/AsyncServletWorker.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Worker class for the asynchronous Servlet API.
88
*
99
* %%
10-
* Copyright (C) 2011 - 2013 MPIWG Berlin
10+
* Copyright (C) 2011 - 2025 MPIWG Berlin
1111
* %%
1212
* This program is free software: you can redistribute it and/or modify
1313
* it under the terms of the GNU Lesser General Public License as
@@ -38,7 +38,6 @@
3838
import org.slf4j.LoggerFactory;
3939

4040
import digilib.conf.DigilibConfiguration;
41-
import digilib.conf.DigilibOption;
4241
import digilib.image.DocuImage;
4342
import digilib.image.ImageJobDescription;
4443
import digilib.image.ImageOpException;
@@ -108,14 +107,10 @@ public void run() {
108107
return;
109108
}
110109
/*
111-
* set forced destination image type
110+
* get destination image type
112111
*/
113-
String mt = null;
114-
if (jobinfo.getRequest().hasOption(DigilibOption.jpg)) {
115-
mt = "image/jpeg";
116-
} else if (jobinfo.getRequest().hasOption(DigilibOption.png)) {
117-
mt = "image/png";
118-
}
112+
String mt = jobinfo.getOutputMimeType();
113+
119114
/*
120115
* send the image
121116
*/

0 commit comments

Comments
 (0)