1
|
/**
|
2
|
* Copyright (C) 2020 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.api.service.media;
|
10
|
|
11
|
import java.awt.Point;
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.Collection;
|
15
|
import java.util.List;
|
16
|
|
17
|
/**
|
18
|
* Factory class to create default media transformations
|
19
|
*
|
20
|
* @author a.kohlbecker
|
21
|
* @since Jul 15, 2020
|
22
|
*/
|
23
|
public class DefaultMediaTransformations {
|
24
|
|
25
|
/**
|
26
|
* Create default transformations for the diglilib server:
|
27
|
* <p>
|
28
|
* Links:
|
29
|
* <ul>
|
30
|
* <li>https://robcast.github.io/digilib/scaler-api.html</li>
|
31
|
* <li>https://robcast.github.io/digilib/iiif-api.html</li>
|
32
|
* </ul>
|
33
|
*
|
34
|
* @return
|
35
|
*/
|
36
|
static public List<MediaUriTransformation> digilib() {
|
37
|
|
38
|
List<MediaUriTransformation> defaultTransformations = new ArrayList<>();
|
39
|
|
40
|
/*
|
41
|
* dataPortalPreviewImage:
|
42
|
* image which fits the default preview image size which is
|
43
|
* for example used in the taxon general page, max extend of the resulting images is 400px
|
44
|
*/
|
45
|
String dataPortalPreviewImage = "digilib/Scaler/IIIF/$1!$2/full/!400,400/0/default.jpg";
|
46
|
Point dataPortalPreviewImageSize = new Point(400,400);
|
47
|
|
48
|
/*
|
49
|
* universalViewerThumbnail:
|
50
|
* crop to fit into a 200 x 147 preview box, the uvfix=1 parameter is used to
|
51
|
* prevent the universal viewer from corrupting the last query parameter. UV appends a parameter t with
|
52
|
* question mark character which causes problems for the URI query parser see https://dev.e-taxonomy.eu/redmine/issues/9132#note-8
|
53
|
*/
|
54
|
String universalViewerThumbnail = "digilib/Scaler/?fn=$1/$2&mo=crop&dw=200&dh=147&uvfix=1";
|
55
|
Point universalViewerThumbnailSize = new Point(200,147);
|
56
|
|
57
|
MediaUriTransformation tr1 = new MediaUriTransformation();
|
58
|
tr1.setPathQueryFragment(new SearchReplace("digilib/Scaler/IIIF/([^\\!]+)\\!([^\\/]+)(.*)", dataPortalPreviewImage));
|
59
|
tr1.setHost(new SearchReplace("pictures.bgbm.org", "pictures.bgbm.org")); // host part only used for matching, no replace!
|
60
|
tr1.setMimeType("image/jpeg");
|
61
|
tr1.setWidth(dataPortalPreviewImageSize.x);
|
62
|
tr1.setHeight(dataPortalPreviewImageSize.y);
|
63
|
tr1.setMaxExtend(true);
|
64
|
|
65
|
MediaUriTransformation tr2 = new MediaUriTransformation();
|
66
|
tr2.setPathQueryFragment(new SearchReplace("digilib/Scaler/IIIF/([^\\!]+)\\!([^\\/]+)(.*)", universalViewerThumbnail));
|
67
|
tr2.setHost(new SearchReplace("pictures.bgbm.org", "pictures.bgbm.org")); // host part only used for matching, no replace!
|
68
|
tr2.setMimeType("image/jpeg");
|
69
|
tr2.setWidth(universalViewerThumbnailSize.x);
|
70
|
tr2.setHeight(universalViewerThumbnailSize.y);
|
71
|
tr2.setMaxExtend(false);
|
72
|
|
73
|
MediaUriTransformation tr3 = new MediaUriTransformation();
|
74
|
tr3.setPathQueryFragment(new SearchReplace("digilib/Scaler/?\\?fn=([^\\\\/]+)/(\\w+)(.*)", dataPortalPreviewImage));
|
75
|
tr3.setHost(new SearchReplace("pictures.bgbm.org", "pictures.bgbm.org")); // host part only used for matching, no replace!
|
76
|
tr3.setMimeType("image/jpeg");
|
77
|
tr3.setWidth(dataPortalPreviewImageSize.x);
|
78
|
tr3.setHeight(dataPortalPreviewImageSize.y);
|
79
|
tr3.setMaxExtend(true);
|
80
|
|
81
|
MediaUriTransformation tr4 = new MediaUriTransformation();
|
82
|
tr4.setPathQueryFragment(new SearchReplace("digilib/Scaler/?\\?fn=([^\\\\/]+)/(\\w+)(.*)", universalViewerThumbnail));
|
83
|
tr4.setHost(new SearchReplace("pictures.bgbm.org", "pictures.bgbm.org")); // host part only used for matching, no replace!
|
84
|
tr4.setMimeType("image/jpeg");
|
85
|
tr4.setWidth(universalViewerThumbnailSize.x);
|
86
|
tr4.setHeight(universalViewerThumbnailSize.y);
|
87
|
tr4.setMaxExtend(false);
|
88
|
|
89
|
defaultTransformations.add(tr2);
|
90
|
defaultTransformations.add(tr1);
|
91
|
defaultTransformations.add(tr3);
|
92
|
defaultTransformations.add(tr4);
|
93
|
|
94
|
return defaultTransformations;
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* Transforms a BGBM digilib image server URI like
|
99
|
*
|
100
|
* https://pictures.bgbm.org/digilib/Scaler?fn=Cyprus/Sisymbrium_aegyptiacum_C1.jpg&mo=file
|
101
|
*
|
102
|
* to a <a href="https://github.com/cybertaxonomy/MediaInfoService">MediaInfoService</a> URI:
|
103
|
*
|
104
|
* https://image.bgbm.org/metadata/info?file=Cyprus/Sisymbrium_aegyptiacum_C1.jpg
|
105
|
*/
|
106
|
static public Collection<MediaUriTransformation> bgbmMediaMetadataService() {
|
107
|
MediaUriTransformation mutScalerAPI = new MediaUriTransformation();
|
108
|
mutScalerAPI.setHost(new SearchReplace("pictures.bgbm.org", "image.bgbm.org"));
|
109
|
mutScalerAPI.setPathQueryFragment(new SearchReplace("digilib\\/Scaler\\?fn=([^&]+)&mo=file", "metadata/info?file=$1"));
|
110
|
|
111
|
// https://pictures.bgbm.org/digilib/Scaler/IIIF/Cichorieae!Lactuca_serriola_Bc_08.jpg/full/full/0/default.jpg
|
112
|
MediaUriTransformation mutIIIFAPI_1segment = new MediaUriTransformation();
|
113
|
mutIIIFAPI_1segment.setHost(new SearchReplace("pictures.bgbm.org", "image.bgbm.org"));
|
114
|
mutIIIFAPI_1segment.setPathQueryFragment(new SearchReplace("digilib\\/Scaler\\/IIIF\\/([^\\/!]+)\\/full/.*", "metadata/info?file=$1"));
|
115
|
|
116
|
MediaUriTransformation mutIIIFAPI_2segments = new MediaUriTransformation();
|
117
|
mutIIIFAPI_2segments.setHost(new SearchReplace("pictures.bgbm.org", "image.bgbm.org"));
|
118
|
mutIIIFAPI_2segments.setPathQueryFragment(new SearchReplace("digilib\\/Scaler\\/IIIF\\/([^\\/!]+)!([^\\/!]+)\\/full/.*", "metadata/info?file=$1/$2"));
|
119
|
|
120
|
MediaUriTransformation mutIIIFAPI_3segments = new MediaUriTransformation();
|
121
|
mutIIIFAPI_3segments.setHost(new SearchReplace("pictures.bgbm.org", "image.bgbm.org"));
|
122
|
mutIIIFAPI_3segments.setPathQueryFragment(new SearchReplace("digilib\\/Scaler\\/IIIF\\/([^\\/!]+)!([^\\/!]+)!([^\\/!]+)\\/full/.*", "metadata/info?file=$1/$2/$3"));
|
123
|
return Arrays.asList(mutScalerAPI, mutIIIFAPI_1segment, mutIIIFAPI_2segments, mutIIIFAPI_3segments);
|
124
|
}
|
125
|
}
|