jalik / meteor-jalik-ufs

Upload File System for Meteor **DISCONTINUED**
MIT License
100 stars 29 forks source link

Using transform function not working #36

Closed braadworst closed 8 years ago

braadworst commented 8 years ago

I cannot get the transform function to work, it throws an error on const in imagemagick-stream. That's because it is ES6 and meteors version of node isn't eating that. I was curious which version you used with imagemagick-stream. Cause I tried them all to no avail.

Furthermore, I tried gm.

var gm = Npm.require('gm');
gm(from)
.resize(50,50)
.stream()
.pipe(to);

This didn't throw an error, but it also didn't generate a thumb that was 50x50 pixels.

Can you shine some light on how you got it to work?

Cheers,

Roy

jalik commented 8 years ago

Hi, I am using Node v0.10.40.

I found difficult to find a nodejs lib that is easy to install because of dependencies, currently I am stuck on an old ubuntu with old nodejs and GYP is the main problem, I managed to get it work but it's very fragile.

The current code is working for me :

photos100Store = new UploadFS.store.Local({
    collection: db.photos100,
    name: 'photos100',
    path: '/uploads/photos-100',
    filter: new UploadFS.Filter({
        maxSize: 1024 * 1000,
        contentTypes: ['image/*'],
        extensions: ['jpg', 'jpeg', 'png']
    }),
    transformWrite: function (from, to, fileId, file) {
        if (gm) {
            gm(from)
                .resize(100, 100)
                .gravity('Center')
                .extent(100, 100)
                .quality(80)
                .stream().pipe(to);
        } else {
            console.error("gm is not available", file);
        }
    }
});
braadworst commented 8 years ago

Hey Jalik,

thanks, for your quick answer, in the meantime, I switched to https://github.com/VeliovGroup/Meteor-Files

I had some more issues with my setup and I didn't want to spent much more time on it. When you load the image in the template, the path doesn't work properly on android phone because it is pointing to localhost (url field in schema). Thanks anyway though, might start using it in the future again, like the interface of it.

Cheers

jalik commented 8 years ago

Hey @braadworst, no problem, but just to be sure, have you encountered any bugs ? I am not sure if I understand the problem with the URL attribute, it is an absolute path I get using Meteor.absolutePath(), I haven't tested UFS using the cordova target build. But I found something you might try next time :

Defining ROOT_URL environment variable : http://stackoverflow.com/questions/15541918/cant-override-meteor-absoluteurl

Happy coding.

sbalbalosa commented 8 years ago

@jalik I'm just wondering do I need to encapsulate the code inside transformWrite within an if statement checking if it is in server environment?

transformWrite: (readStream, writeStream, fileId, file) => { if (Meteor.isServer) { const gm = require('gm'); gm(readStream).crop( file.width, file.height, file.x, file.y ).stream().pipe(writeStream); } },

jalik commented 8 years ago

@sbalbalosa, the transformRead and transformWrite are server side methods only, so you don't need to encapsulate.

ansaries commented 8 years ago

hi jalik, i followed the tutorial of socially and constructed my app with UploadFS which is working find for normal files upload. but when i use image transform it doesnt transform. following is my code: transformWrite: (from, to, fileId, file) => { if (Meteor.isServer) { const gm = Npm.require('gm'); if (gm) { gm(from) .resize(30, 30) .gravity('Center') .extent(30, 30) .quality(80) .stream() .pipe(to); } else { console.error('im is not available', file); } } }, i tried with imagemagick-stream also but it has ES5 to 6 compatibility issues. My node version is 4.4.5, npm is 3.10.5, meteor is 1.3.4.4 and i am running the code with Angular 1.5 ES6 using meteor.

"dependencies": { "angular": "^1.5.7", "angular-animate": "^1.5.3", "angular-aria": "^1.5.3", "angular-google-maps": "^2.3.2", "angular-material": "1.0.7", "angular-messages": "^1.5.7", "angular-meteor": "^1.3.9", "angular-sanitize": "^1.5.7", "angular-simple-logger": "^0.1.7", "angular-sortable-view": "0.0.15", "angular-ui-router": "^0.2.18", "angular-utils-pagination": "^0.11.1", "fs": "0.0.2", "gm": "^1.22.0", "imagemagick": "^0.1.3", "imagemagick-stream": "^4.1.0", "ionic-sdk": "^1.2.4", "meteor-node-stubs": "~0.2.0", "ng-file-upload": "^12.0.4", "ng-img-crop": "^0.2.0", "underscore": "^1.8.3"

just for your reference above is my package.json. please tell me where am i make a mistake. or what is the work around.

jalik commented 8 years ago

@ansaries did you install the gm package using NPM ? Install the package globally (for the system) by executing the following command : npm install -g gm

Also be sure that you have installed gm dependencies, on Debian do like below : sudo apt-get install imagemagick graphicsmagick

jalik commented 8 years ago

This issue is mainly related to dependencies, not to UploadFS, so I close the issue until there is really a bug. Thank you for your feedback.