Permalink
Browse files

raw examples

  • Loading branch information...
1 parent a425aac commit 6ac2359b75b7111b4b7d7095950d0ed8b27bf9ad @filiptepper committed May 24, 2012
Showing with 51 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +30 −0 raw/raw.js
  3. +20 −0 raw/raw.rb
View
@@ -1,4 +1,5 @@
.DS_Store
+.rbx
log
tmp
node_modules
View
@@ -0,0 +1,30 @@
+'use strict';
+
+var gm = require("gm")
+ , fs = require("fs")
+
+ , output = fs.createWriteStream("/dev/null")
+ , image = "../image.jpg"
+ , limit = 2, count = 1000;
+
+(function self() {
+ --count;
+ --limit;
+ gm(image)
+ .resize(100, 100)
+ .stream("jpg", function(err, stdout, stderr) {
+ if (err) {
+ throw err;
+ }
+ stdout.pipe(output);
+ stdout.on('end', function () {
+ ++limit;
+ if (count) {
+ self();
+ }
+ });
+ });
+ if (limit && count) {
+ self();
+ }
+}());
View
@@ -0,0 +1,20 @@
+count = 1000
+limit = 2
+
+1.upto(count / limit) do
+ threads = []
+
+ 1.upto(limit) do
+ threads << Thread.new do
+ IO.popen("/usr/local/bin/gm convert -size 100x100 ../image.jpg -resize 100x100 JPG:-") do |result|
+ devnull = File.open("/dev/null", "w")
+
+ while part = result.read(1024)
+ devnull.puts(part)
+ end
+ end
+ end
+ end
+
+ threads.join
+end

0 comments on commit 6ac2359

Please sign in to comment.