This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I8de3441d59d4d78f0f154b69f7d4670ed9688b90
- Loading branch information
Showing
14 changed files
with
426 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ source :rubygems | |
|
||
gem "sinatra" | ||
gem "rmagick" | ||
gem "mini_magick" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
sinatra/sinatra_rmagick/app.rb → sinatra/sinatra_imagemagick/app.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
require "rubygems" | ||
require "sinatra" | ||
require "RMagick" | ||
require "mini_magick" | ||
|
||
get "/" do | ||
content_type "text/plain" | ||
|
||
image = MiniMagick::Image.open("imagemagick.jpg") | ||
image.resize("100x100!") | ||
|
||
return "minimagick failed" unless image[:width] == 100 && image[:height] == 100 | ||
|
||
img = Magick::ImageList.new("imagemagick.jpg") | ||
cropped = img.crop(50, 15, 150, 165) | ||
cropped.write("thumb.jpg") | ||
|
||
thumb = Magick::Image::read("thumb.jpg").first | ||
if thumb.format == "JPEG" && thumb.columns == 150 && thumb.rows == 165 | ||
"hello from rmagick" | ||
"hello from imagemagick" | ||
end | ||
end | ||
end |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.cloudfoundry</groupId> | ||
<artifactId>imagemagick</artifactId> | ||
<name>spring_imagemagick</name> | ||
<packaging>war</packaging> | ||
<version>1.0.0-BUILD-SNAPSHOT</version> | ||
<properties> | ||
<java-version>1.6</java-version> | ||
<org.springframework-version>3.1.0.RELEASE</org.springframework-version> | ||
<org.aspectj-version>1.6.9</org.aspectj-version> | ||
<org.slf4j-version>1.5.10</org.slf4j-version> | ||
</properties> | ||
<dependencies> | ||
<!-- Spring --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>${org.springframework-version}</version> | ||
<exclusions> | ||
<!-- Exclude Commons Logging in favor of SLF4j --> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${org.springframework-version}</version> | ||
</dependency> | ||
|
||
<!-- AspectJ --> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjrt</artifactId> | ||
<version>${org.aspectj-version}</version> | ||
</dependency> | ||
|
||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${org.slf4j-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>${org.slf4j-version}</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>${org.slf4j-version}</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<version>1.2.15</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.mail</groupId> | ||
<artifactId>mail</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>javax.jms</groupId> | ||
<artifactId>jms</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>com.sun.jdmk</groupId> | ||
<artifactId>jmxtools</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>com.sun.jmx</groupId> | ||
<artifactId>jmxri</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<!-- @Inject --> | ||
<dependency> | ||
<groupId>javax.inject</groupId> | ||
<artifactId>javax.inject</artifactId> | ||
<version>1</version> | ||
</dependency> | ||
|
||
<!-- Servlet --> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet.jsp</groupId> | ||
<artifactId>jsp-api</artifactId> | ||
<version>2.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.7</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-eclipse-plugin</artifactId> | ||
<version>2.9</version> | ||
<configuration> | ||
<additionalProjectnatures> | ||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> | ||
</additionalProjectnatures> | ||
<additionalBuildcommands> | ||
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> | ||
</additionalBuildcommands> | ||
<downloadSources>true</downloadSources> | ||
<downloadJavadocs>true</downloadJavadocs> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<compilerArgument>-Xlint:all</compilerArgument> | ||
<showWarnings>true</showWarnings> | ||
<showDeprecation>true</showDeprecation> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.2.1</version> | ||
<configuration> | ||
<mainClass>org.test.int1.Main</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
39 changes: 39 additions & 0 deletions
39
spring/spring_imagemagick/src/main/java/org/cloudfoundry/imagemagick/HomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.cloudfoundry.imagemagick; | ||
|
||
import java.lang.ClassLoader; | ||
import javax.inject.Inject; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
/** | ||
* Handles requests for the application home page. | ||
*/ | ||
@Controller | ||
public class HomeController { | ||
|
||
@Inject | ||
private MagickProcesser magickProcesser; | ||
/** | ||
* Simply selects the home view to render by returning its name. | ||
*/ | ||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public String home(Model model) { | ||
|
||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
String path = classLoader.getResource("imagemagick.jpg").getPath(); | ||
|
||
if (magickProcesser.resize(path, "100x100")) { | ||
// Resize was successful | ||
String newSize = magickProcesser.getSize(path); | ||
|
||
if (new String("100x100").equals(newSize)) { | ||
model.addAttribute("message", "hello from imagemagick"); | ||
} | ||
} | ||
|
||
return "home"; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
spring/spring_imagemagick/src/main/java/org/cloudfoundry/imagemagick/MagickProcesser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.cloudfoundry.imagemagick; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.BufferedReader; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MagickProcesser { | ||
|
||
public boolean identify() { | ||
return runCmd("identify"); | ||
} | ||
|
||
// Returns true if command execution was successful | ||
public boolean resize(String path, String newSize) { | ||
// This method overwrites existing image with the resized one | ||
return runCmd("convert -resize " + newSize + "! " + path + " " + path); | ||
} | ||
|
||
public String getSize(String path) { | ||
// This method overwrites existing image with the resized one | ||
return getCmdOutput("identify -format %wx%h " + path); | ||
} | ||
|
||
private boolean runCmd(String cmd) { | ||
Process process; | ||
try { | ||
process = Runtime.getRuntime().exec(cmd); | ||
try { | ||
process.waitFor(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
return (process.exitValue() == 0); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
private String getCmdOutput(String cmd) { | ||
Process process; | ||
try { | ||
process = Runtime.getRuntime().exec(cmd); | ||
InputStream cmdOut = process.getInputStream(); | ||
InputStreamReader reader = new InputStreamReader(cmdOut); | ||
BufferedReader in = new BufferedReader(reader); | ||
String output = ""; | ||
String line; | ||
while ((line = in.readLine()) != null) { | ||
output += line; | ||
} | ||
return output; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return ""; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd"> | ||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> | ||
|
||
<!-- Appenders --> | ||
<appender name="console" class="org.apache.log4j.ConsoleAppender"> | ||
<param name="Target" value="System.out" /> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%-5p: %c - %m%n" /> | ||
</layout> | ||
</appender> | ||
|
||
<!-- Application Loggers --> | ||
<logger name="org.cloudfoundry.imagemagick"> | ||
<level value="info" /> | ||
</logger> | ||
|
||
<!-- 3rdparty Loggers --> | ||
<logger name="org.springframework.core"> | ||
<level value="info" /> | ||
</logger> | ||
|
||
<logger name="org.springframework.beans"> | ||
<level value="info" /> | ||
</logger> | ||
|
||
<logger name="org.springframework.context"> | ||
<level value="info" /> | ||
</logger> | ||
|
||
<logger name="org.springframework.web"> | ||
<level value="info" /> | ||
</logger> | ||
|
||
<!-- Root Logger --> | ||
<root> | ||
<priority value="warn" /> | ||
<appender-ref ref="console" /> | ||
</root> | ||
|
||
</log4j:configuration> |
28 changes: 28 additions & 0 deletions
28
spring/spring_imagemagick/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans:beans xmlns="http://www.springframework.org/schema/mvc" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:beans="http://www.springframework.org/schema/beans" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> | ||
|
||
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> | ||
|
||
<!-- Enables the Spring MVC @Controller programming model --> | ||
<annotation-driven /> | ||
|
||
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> | ||
<resources mapping="/resources/**" location="/resources/" /> | ||
|
||
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> | ||
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | ||
<beans:property name="prefix" value="/WEB-INF/views/" /> | ||
<beans:property name="suffix" value=".jsp" /> | ||
</beans:bean> | ||
|
||
<context:component-scan base-package="org.cloudfoundry.imagemagick" /> | ||
|
||
|
||
|
||
</beans:beans> |
10 changes: 10 additions & 0 deletions
10
spring/spring_imagemagick/src/main/webapp/WEB-INF/spring/root-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> | ||
|
||
<!-- Root Context: defines shared resources visible to all other web components --> | ||
|
||
<bean id="magickProcesser" class="org.cloudfoundry.imagemagick.MagickProcesser"/> | ||
|
||
</beans> |
Oops, something went wrong.