Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
ImageMagick tests for Java 6 and 7
Browse files Browse the repository at this point in the history
Change-Id: I8de3441d59d4d78f0f154b69f7d4670ed9688b90
  • Loading branch information
mariash committed Aug 17, 2012
1 parent 520a38f commit aef18f5
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ source :rubygems

gem "sinatra"
gem "rmagick"
gem "mini_magick"
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
GEM
remote: http://rubygems.org/
specs:
mini_magick (3.4)
subexec (~> 0.2.1)
rack (1.4.1)
rack-protection (1.2.0)
rack
Expand All @@ -9,11 +11,13 @@ GEM
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
subexec (0.2.2)
tilt (1.3.3)

PLATFORMS
ruby

DEPENDENCIES
mini_magick
rmagick
sinatra
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
158 changes: 158 additions & 0 deletions spring/spring_imagemagick/pom.xml
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>
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";
}
}
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.
41 changes: 41 additions & 0 deletions spring/spring_imagemagick/src/main/resources/log4j.xml
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>
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>
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>
Loading

0 comments on commit aef18f5

Please sign in to comment.