| ThumbnailBuilder.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 *
5 *
6 *
7 * The contents of this file are subject to the terms of the Liferay Enterprise
8 * Subscription License ("License"). You may not use this file except in
9 * compliance with the License. You can obtain a copy of the License by
10 * contacting Liferay, Inc. See the License for the specific language governing
11 * permissions and limitations under the License, including but not limited to
12 * distribution rights of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.tools;
24
25 import com.liferay.portal.image.ImageProcessorImpl;
26 import com.liferay.portal.kernel.image.ImageBag;
27 import com.liferay.portal.kernel.util.GetterUtil;
28
29 import java.awt.image.RenderedImage;
30
31 import java.io.File;
32
33 import javax.imageio.ImageIO;
34
35 /**
36 * <a href="ThumbnailBuilder.java.html"><b><i>View Source</i></b></a>
37 *
38 * @author Brian Wing Shun Chan
39 */
40 public class ThumbnailBuilder {
41
42 public static void main(String[] args) {
43 File originalFile = new File(
44 System.getProperty("thumbnail.original.file"));
45 File thumbnailFile = new File(
46 System.getProperty("thumbnail.thumbnail.file"));
47 int height = GetterUtil.getInteger(
48 System.getProperty("thumbnail.height"));
49 int width = GetterUtil.getInteger(
50 System.getProperty("thumbnail.width"));
51 boolean overwrite = GetterUtil.getBoolean(
52 System.getProperty("thumbnail.overwrite"));
53
54 new ThumbnailBuilder(
55 originalFile, thumbnailFile, height, width, overwrite);
56 }
57
58 public ThumbnailBuilder(
59 File originalFile, File thumbnailFile, int height, int width,
60 boolean overwrite) {
61
62 try {
63 if (!originalFile.exists()) {
64 return;
65 }
66
67 if (!overwrite) {
68 if (thumbnailFile.lastModified() >
69 originalFile.lastModified()) {
70
71 return;
72 }
73 }
74
75 ImageBag imageBag = _imageProcessorUtil.read(originalFile);
76
77 RenderedImage thumbnail = _imageProcessorUtil.scale(
78 imageBag.getRenderedImage(), height, width);
79
80 ImageIO.write(thumbnail, imageBag.getType(), thumbnailFile);
81 }
82 catch (Exception e) {
83 e.printStackTrace();
84 }
85 }
86
87 private static ImageProcessorImpl _imageProcessorUtil =
88 ImageProcessorImpl.getInstance();
89
90 }