]> source.dussan.org Git - gitblit.git/commitdiff
Simplified screenshot process and automated thumbnail generation.
authorJames Moger <james.moger@gitblit.com>
Thu, 9 Jun 2011 23:41:53 +0000 (19:41 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 9 Jun 2011 23:41:53 +0000 (19:41 -0400)
21 files changed:
build.xml
docs/screenshots/image_processing.txt
docs/screenshots/raw/00.png [deleted file]
docs/screenshots/raw/01.png [deleted file]
docs/screenshots/raw/02.png [deleted file]
docs/screenshots/raw/03.png [deleted file]
docs/screenshots/raw/04.png [deleted file]
docs/screenshots/raw/05.png [deleted file]
docs/screenshots/raw/06.png [deleted file]
docs/screenshots/raw/07.png [deleted file]
docs/screenshots/raw/08.png [deleted file]
docs/screenshots/thumbs/00.png [deleted file]
docs/screenshots/thumbs/01.png [deleted file]
docs/screenshots/thumbs/02.png [deleted file]
docs/screenshots/thumbs/03.png [deleted file]
docs/screenshots/thumbs/04.png [deleted file]
docs/screenshots/thumbs/05.png [deleted file]
docs/screenshots/thumbs/06.png [deleted file]
docs/screenshots/thumbs/07.png [deleted file]
docs/screenshots/thumbs/08.png [deleted file]
src/com/gitblit/Thumbnailer.java [new file with mode: 0644]

index c41b788abd710e256262b7bb8fd354f87a7922bf..ddb0dfbf1669b90284d68723acb5dd8cd3ea21cd 100644 (file)
--- a/build.xml
+++ b/build.xml
                        </fileset>\r
                </copy>\r
 \r
-               <!-- Copy screenshot thumbnails -->\r
-               <mkdir dir="${basedir}/site/thumbs" />\r
-               <copy todir="${basedir}/site/thumbs">\r
-                       <fileset dir="${basedir}/docs/screenshots/thumbs">\r
-                               <include name="*.png" />\r
-                       </fileset>\r
-               </copy>\r
+               <!-- Generate thumbnails of screenshots -->\r
+               <java classpath="${project.build.dir}" classname="com.gitblit.Thumbnailer">\r
+                       <classpath refid="master-classpath" />\r
+                               \r
+                       <arg value="--sourceFolder" />\r
+                       <arg value="${basedir}/docs/screenshots" />\r
+               \r
+                       <arg value="--destinationFolder" />\r
+                       <arg value="${basedir}/site/thumbs" />\r
+                       \r
+                       <arg value="--maximumDimension" />\r
+                       <arg value="250" />\r
+               </java>\r
 \r
                <!-- Copy screenshots -->\r
                <mkdir dir="${basedir}/site/screenshots" />\r
index de1d102b43daa8650da8e73f2d238f40e489817b..d034062cf567dc6709cb3f1907ae11182c5a3452 100644 (file)
@@ -1,5 +1,6 @@
-1. Install GIMP\r
-2. Download and install David's Batch Processor (DBP) http://members.ozemail.com.au/~hodsond/dbp.html\r
-3. Make screenshots and put them in "screenshots\raw"\r
-4. Using DBP, crop the images to 1007x661 and output PNGs to "screenshots"\r
-5. Using DBP, resize the cropped images to 0.25 with a blur of 1.0 and put PNGs in "screenshots\thumbs"
\ No newline at end of file
+1. Install Firefox\r
+2. Install "Awesome Screenshot" add-on\r
+3. Set browser size to 1024x768\r
+4. Save "visible part" screenshots as png to screenshots folder\r
+\r
+Screenshot thumbnails are automatically generated during build script execution. 
\ No newline at end of file
diff --git a/docs/screenshots/raw/00.png b/docs/screenshots/raw/00.png
deleted file mode 100644 (file)
index eb50149..0000000
Binary files a/docs/screenshots/raw/00.png and /dev/null differ
diff --git a/docs/screenshots/raw/01.png b/docs/screenshots/raw/01.png
deleted file mode 100644 (file)
index e626edf..0000000
Binary files a/docs/screenshots/raw/01.png and /dev/null differ
diff --git a/docs/screenshots/raw/02.png b/docs/screenshots/raw/02.png
deleted file mode 100644 (file)
index 8578ca6..0000000
Binary files a/docs/screenshots/raw/02.png and /dev/null differ
diff --git a/docs/screenshots/raw/03.png b/docs/screenshots/raw/03.png
deleted file mode 100644 (file)
index 0fc0351..0000000
Binary files a/docs/screenshots/raw/03.png and /dev/null differ
diff --git a/docs/screenshots/raw/04.png b/docs/screenshots/raw/04.png
deleted file mode 100644 (file)
index d2c1665..0000000
Binary files a/docs/screenshots/raw/04.png and /dev/null differ
diff --git a/docs/screenshots/raw/05.png b/docs/screenshots/raw/05.png
deleted file mode 100644 (file)
index a2fe409..0000000
Binary files a/docs/screenshots/raw/05.png and /dev/null differ
diff --git a/docs/screenshots/raw/06.png b/docs/screenshots/raw/06.png
deleted file mode 100644 (file)
index 4dfc269..0000000
Binary files a/docs/screenshots/raw/06.png and /dev/null differ
diff --git a/docs/screenshots/raw/07.png b/docs/screenshots/raw/07.png
deleted file mode 100644 (file)
index 0b7c412..0000000
Binary files a/docs/screenshots/raw/07.png and /dev/null differ
diff --git a/docs/screenshots/raw/08.png b/docs/screenshots/raw/08.png
deleted file mode 100644 (file)
index 9c37663..0000000
Binary files a/docs/screenshots/raw/08.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/00.png b/docs/screenshots/thumbs/00.png
deleted file mode 100644 (file)
index 636631f..0000000
Binary files a/docs/screenshots/thumbs/00.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/01.png b/docs/screenshots/thumbs/01.png
deleted file mode 100644 (file)
index 66bd6d0..0000000
Binary files a/docs/screenshots/thumbs/01.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/02.png b/docs/screenshots/thumbs/02.png
deleted file mode 100644 (file)
index 316be98..0000000
Binary files a/docs/screenshots/thumbs/02.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/03.png b/docs/screenshots/thumbs/03.png
deleted file mode 100644 (file)
index e141348..0000000
Binary files a/docs/screenshots/thumbs/03.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/04.png b/docs/screenshots/thumbs/04.png
deleted file mode 100644 (file)
index eeee2ec..0000000
Binary files a/docs/screenshots/thumbs/04.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/05.png b/docs/screenshots/thumbs/05.png
deleted file mode 100644 (file)
index c60dc58..0000000
Binary files a/docs/screenshots/thumbs/05.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/06.png b/docs/screenshots/thumbs/06.png
deleted file mode 100644 (file)
index 3e27890..0000000
Binary files a/docs/screenshots/thumbs/06.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/07.png b/docs/screenshots/thumbs/07.png
deleted file mode 100644 (file)
index 4212d30..0000000
Binary files a/docs/screenshots/thumbs/07.png and /dev/null differ
diff --git a/docs/screenshots/thumbs/08.png b/docs/screenshots/thumbs/08.png
deleted file mode 100644 (file)
index 7432d3f..0000000
Binary files a/docs/screenshots/thumbs/08.png and /dev/null differ
diff --git a/src/com/gitblit/Thumbnailer.java b/src/com/gitblit/Thumbnailer.java
new file mode 100644 (file)
index 0000000..5976f25
--- /dev/null
@@ -0,0 +1,134 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit;\r
+\r
+import java.awt.Dimension;\r
+import java.awt.Image;\r
+import java.awt.image.BufferedImage;\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.FilenameFilter;\r
+import java.io.IOException;\r
+import java.util.Iterator;\r
+\r
+import javax.imageio.ImageIO;\r
+import javax.imageio.ImageReader;\r
+import javax.imageio.stream.ImageInputStream;\r
+\r
+import com.beust.jcommander.JCommander;\r
+import com.beust.jcommander.Parameter;\r
+import com.beust.jcommander.ParameterException;\r
+import com.beust.jcommander.Parameters;\r
+\r
+public class Thumbnailer {\r
+\r
+       public static void main(String[] args) {\r
+               Params params = new Params();\r
+               JCommander jc = new JCommander(params);\r
+               try {\r
+                       jc.parse(args);\r
+               } catch (ParameterException t) {\r
+                       System.err.println(t.getMessage());\r
+                       jc.usage();\r
+               }\r
+               createImageThumbnail(params.sourceFolder, params.destinationFolder, params.maximumDimension);\r
+       }\r
+\r
+       public static void createImageThumbnail(String sourceFolder, String destinationFolder,\r
+                       int maxDimension) {\r
+               if (maxDimension <= 0)\r
+                       return;\r
+               File source = new File(sourceFolder);\r
+               File destination = new File(destinationFolder);\r
+               destination.mkdirs();\r
+               File[] sourceFiles = source.listFiles(new FilenameFilter() {\r
+                       @Override\r
+                       public boolean accept(File dir, String name) {\r
+                               return name.toLowerCase().endsWith(".png");\r
+                       }\r
+               });\r
+\r
+               for (File sourceFile : sourceFiles) {\r
+                       File destinationFile = new File(destination, sourceFile.getName());\r
+                       try {\r
+                               Dimension sz = getImageDimensions(sourceFile);\r
+                               int w = 0;\r
+                               int h = 0;\r
+                               if (sz.width > maxDimension) {\r
+                                       // Scale to Width\r
+                                       w = maxDimension;\r
+                                       float f = maxDimension;\r
+                                       h = (int) ((f / sz.width) * sz.height); // normalize height\r
+                               } else if (sz.height > maxDimension) {\r
+                                       // Scale to Height\r
+                                       h = maxDimension;\r
+                                       float f = maxDimension;\r
+                                       w = (int) ((f / sz.height) * sz.width); // normalize width\r
+                               } else {\r
+                                       // No thumbnail\r
+                                       return;\r
+                               }\r
+                               System.out.println("Generating thumbnail for " + sourceFile.getName() + " as (" + w\r
+                                               + "," + h + ")");\r
+                               BufferedImage image = ImageIO.read(sourceFile);\r
+                               Image scaledImage = image.getScaledInstance(w, h, BufferedImage.SCALE_SMOOTH);\r
+                               BufferedImage destImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);\r
+                               destImage.createGraphics().drawImage(scaledImage, 0, 0, null);\r
+                               FileOutputStream fos = new FileOutputStream(destinationFile);\r
+                               ImageIO.write(destImage, "png", fos);\r
+                               fos.flush();\r
+                               fos.getFD().sync();\r
+                               fos.close();\r
+                       } catch (Throwable t) {\r
+                               t.printStackTrace();\r
+                       }\r
+               }\r
+       }\r
+\r
+       public static Dimension getImageDimensions(File file) throws IOException {\r
+               ImageInputStream in = ImageIO.createImageInputStream(file);\r
+               try {\r
+                       final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);\r
+                       if (readers.hasNext()) {\r
+                               ImageReader reader = readers.next();\r
+                               try {\r
+                                       reader.setInput(in);\r
+                                       return new Dimension(reader.getWidth(0), reader.getHeight(0));\r
+                               } finally {\r
+                                       reader.dispose();\r
+                               }\r
+                       }\r
+               } finally {\r
+                       if (in != null)\r
+                               in.close();\r
+               }\r
+               return null;\r
+       }\r
+\r
+       @Parameters(separators = " ")\r
+       private static class Params {\r
+\r
+               @Parameter(names = { "--sourceFolder" }, description = "Source folder for raw images", required = true)\r
+               public String sourceFolder;\r
+\r
+               @Parameter(names = { "--destinationFolder" }, description = "Destination folder for thumbnails", required = true)\r
+               public String destinationFolder;\r
+\r
+               @Parameter(names = { "--maxDimension" }, description = "Maximum width or height for thumbnail", required = true)\r
+               public int maximumDimension;\r
+\r
+       }\r
+}\r