Source Code Cross Referenced for ImageMagickResizer.java in  » Content-Management-System » openedit » org » openedit » store » images » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » openedit » org.openedit.store.images 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Sep 20, 2005
003:         */
004:        package org.openedit.store.images;
005:
006:        import java.io.File;
007:        import java.util.ArrayList;
008:        import java.util.List;
009:
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:
013:        import com.openedit.OpenEditException;
014:        import com.openedit.modules.image.ConvertInstructions;
015:        import com.openedit.modules.image.ImageResizer;
016:        import com.openedit.util.Exec;
017:        import com.openedit.util.PathUtilities;
018:
019:        public class ImageMagickResizer extends ImageResizer {
020:            private static final Log log = LogFactory
021:                    .getLog(ImageMagickResizer.class);
022:            protected String fieldCommandName;
023:
024:            public boolean canConvert(String inPath) {
025:                String ext = PathUtilities.extractPageType(inPath);
026:                String mime = getMimeTypeMap().getMimeType(ext);
027:                if (mime.startsWith("image") ||
028:
029:                mime.equals("application/photoshop")) {
030:                    return true;
031:                }
032:
033:                if (!System.getProperty("os.name").toLowerCase().contains(
034:                        "windows")) {
035:                    if (mime.equals("application/postscript")
036:                            || mime.equals("application/pdf")
037:                            || mime.equals("application/illustrator")
038:                            || mime.equals("image/x-eps")) {
039:                        return true;
040:                    }
041:                }
042:
043:                return false;
044:            }
045:
046:            public boolean resizeImage(File inFile, File inOutFile,
047:                    ConvertInstructions inStructions) throws Exception {
048:                List com = createCommand(inFile, inStructions);
049:
050:                com.add("-resize");
051:                com.add((int) inStructions.getMaxScaledSize().getWidth() + "x"
052:                        + (int) inStructions.getMaxScaledSize().getHeight()
053:                        + ">");
054:                com.add("-colorspace");
055:                com.add("rgb");
056:                com.add(inOutFile.getAbsolutePath());
057:
058:                inOutFile.getParentFile().mkdirs();
059:                long start = System.currentTimeMillis();
060:                if (runExec(com)) {
061:                    log.info("Resize complete in:"
062:                            + (System.currentTimeMillis() - start) + " "
063:                            + inOutFile.getName());
064:                    return true;
065:                }
066:                return false;
067:            }
068:
069:            protected List createCommand(File inFile,
070:                    ConvertInstructions inStructions) {
071:                List com = new ArrayList();
072:                //New version of Image Magik are 0 based
073:                int page = inStructions.getPageNumber();
074:                page--;
075:                page = Math.min(0, page);
076:
077:                com.add(getCommandName());
078:                com.add(inFile.getAbsolutePath() + "[" + page + "]");
079:                return com;
080:            }
081:
082:            public void resizeThumbnailImage(File inFile, File inOutFile,
083:                    ConvertInstructions inStructions) throws Exception {
084:
085:                List com = new ArrayList();
086:                com.add(getCommandName());
087:                com.add(inFile.getAbsolutePath() + "["
088:                        + inStructions.getPageNumber() + "]");
089:                com.add("-thumbnail");
090:                com.add((int) inStructions.getMaxScaledSize().getWidth() + "x"
091:                        + (int) inStructions.getMaxScaledSize().getHeight()
092:                        + ">");
093:                com.add(inOutFile.getAbsolutePath());
094:                inOutFile.getParentFile().mkdirs();
095:                long start = System.currentTimeMillis();
096:                if (runExec(com)) {
097:                    log.info("Resize complete in:"
098:                            + (System.currentTimeMillis() - start) + " "
099:                            + inOutFile.getName());
100:                }
101:            }
102:
103:            protected boolean runExec(List inCom) throws OpenEditException {
104:                Exec exec = new Exec();
105:                exec.setTrackOutput(false);
106:                boolean works = exec.runExec(inCom);
107:                if (!works) {
108:                    log
109:                            .info("Resize failed running again with output tracking");
110:                    exec.setTrackOutput(true);
111:                    works = exec.runExec(inCom);
112:                    log.info(exec.getStandardOutput() + " error output:"
113:                            + exec.getErrorOutput());
114:                }
115:                return works;
116:            }
117:
118:            public String getCommandName() {
119:                if (fieldCommandName == null) {
120:                    String env = System.getProperty("IMAGE_MAGICK_COMMAND");
121:                    if (env == null) {
122:                        env = System.getenv("IMAGE_MAGICK_COMMAND");
123:                    }
124:                    if (env == null) {
125:                        if (System.getProperty("os.name").toUpperCase()
126:                                .contains("WINDOWS")) {
127:                            env = "imconvert.exe";
128:                        } else {
129:                            env = "convert";
130:                        }
131:                    }
132:                    fieldCommandName = env;
133:                }
134:
135:                return fieldCommandName;
136:            }
137:
138:            public void setCommandName(String inCommandName) {
139:                fieldCommandName = inCommandName;
140:            }
141:
142:            public List getConvertCommand(File inIn, File inOut,
143:                    int inPageNumber) {
144:                List com = new ArrayList();
145:                com.add(getCommandName());
146:                com.add(inIn.getAbsolutePath() + "[" + inPageNumber + "]");
147:                com.add(inOut.getAbsolutePath());
148:                return com;
149:            }
150:
151:            public boolean convert(File inIn, File inOut,
152:                    ConvertInstructions inStructions) throws OpenEditException {
153:                //if this is an eps output from an ai input then use ghostscript
154:                //try to call convert with a 0-based page index (Image Magick 6.3 series)
155:                List com = getConvertCommand(inIn, inOut, inStructions
156:                        .getPageNumber() - 1);
157:                inOut.getParentFile().mkdirs();
158:                long start = System.currentTimeMillis();
159:                if (runExec(com)) {
160:                    log.info("Resize complete in:"
161:                            + (System.currentTimeMillis() - start) + " output "
162:                            + inOut.getAbsolutePath());
163:                    return true;
164:                } else {
165:                    //TODO: Drop support for old Image Magick versions to clean up code
166:                    log
167:                            .debug("0-based page index failed. Trying 1-based page index");
168:                    //try to call convert with a 0-based page index (older Image Magick)
169:
170:                    com = getConvertCommand(inIn, inOut, inStructions
171:                            .getPageNumber());
172:                    if (runExec(com)) {
173:                        log.info("Resize complete in:"
174:                                + (System.currentTimeMillis() - start)
175:                                + " output " + inOut.getAbsolutePath());
176:                        return true;
177:                    }
178:                    return false;
179:                }
180:
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.