Alvaro Videla avatar Alvaro Videla committed ca0e2e7

resizes image using imagemagick

Comments (0)

Files changed (3)

 var fs = require('fs')
+, im = require('imagemagick')
+, image_storage = require('./image_storage.js')
 , thumper = require('./thumper')
 , user_images = require('../lib/user_images.js')
 ;
     queue: 'resize_queue',
     routingKey: '',
     callback: function(msg, headers, deliveryInfo) {
-        var uploadDir = __dirname + "/../public/uploads";
-        im.resize({
-            srcPath: uploadDir + "/" + msg.filename,
-            dstPath: uploadDir + "/small_" + msg.filename,
-            width:   256,
-            heigth: 256
-        }, function(err, stdout, stderr){
-            if (err) {
-                console.log(err, stdout, stderr);
-            } else {
-                console.log("resized image");
-                thumper.publishMessage('cloudstagram-new-image', msg, '');   
-            }
+        console.log("__dirname", __dirname);
+        filename = "small_" + msg.filename;
+        tmpPath = __dirname + "/../tmp/" + filename;
+        image_storage.readGsFile(msg.filename, function(error, gsData) {
+            console.log('readGsFile');
+            im.resize({
+                srcData: gsData.binary,
+                dstPath: tmpPath,
+                width:   225
+            }, function(err, stdout, stderr){
+                console.log('storeFile');
+                image_storage.storeFile(tmpPath, filename, gsData.gsObject.contentType, function(error, data) {
+                    console.log("deleting temporary file: ", tmpPath);
+                    fs.unlink(tmpPath);
+                    thumper.publishMessage('cloudstagram-new-image', msg, '');
+                });
+            });
         });
     }
 };
 
 exports.startConsumers = function() {
     thumper.startConsumers([
+        resize_consumer,
         add_image_to_user_consumer, 
         new_image_consumer,
         image_to_followers_consumer,

public/javascripts/image_box.ejs

     </span>
   </div>
   <div>
-    <a href="/image/<%= image.path %>" rel="lightbox" <% if (image.comment) { %>title="<%= image.comment %>"<% } %>><img class="userimage" src="/image/<%= image.path %>" data-id="<%= image.path %>" data-owner="<%= image.username %>"></img></a>
+    <a href="/image/<%= image.path %>" rel="lightbox" <% if (image.comment) { %>title="<%= image.comment %>"<% } %>><img class="userimage" src="/image/small_<%= image.path %>" data-id="<%= image.path %>" data-owner="<%= image.username %>"></img></a>
   </div>
   <% if (loggedin && ((typeof data.related == "undefined") || data.related[i].indexOf(loggedinuser) == -1 )) { %>
   <div class="like-action">

routes/upload_image.js

                 uploaded: ISODateString(new Date()),
                 mime: mimeType
             };
-            thumper.publishMessage('cloudstagram-new-image', fileData, '');
+            thumper.publishMessage('cloudstagram-upload', fileData, '');
             delete req.session.upload_error;
             var response = "success|The image was uploaded succesfully "
                       + "and is being processed by our services.|upload-" + filename;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.