Using GraphicsMagick to compress image

I am using Ionic2rc4 and want to use GraphicsMagick library.

After using Camera plugin taking a picture / from photolibrary, use GraphicsMagick to compress the photo before upload it to server.
What I have done was…

npm install gm --save
npm install @types/gm --save

in declarations.d.ts

declare module 'gm';

After that using

import { gm } from 'gm';

gm(image).identify(function (err, value) {
                if (!err) console.log('file identify', value);
            })

and then when ionic run android, it comes an error
" Uncaught Error : Cannot find module “child_process”.

Anyone have try this GraphicsMagick with ionic2rc4 ?
Please kindly help me.
Thanks in advance.

1 Like

I don’t think that library is going to run in a browser environment. I would look into other options like j-i-c.

1 Like

Hi @rapropos,

Could you look into this https://angular-meteor.com/tutorials/socially/angular2/files-and-uploadfs ?
This tutorial is using GraphicsMagick library.

But I still don’t know how to use it with ionic2.
Please kindly help me.
Thanks in advance.

I believe Meteor replaces the browser, so it’s a different runtime environment than Ionic is accustomed to.

The technique I used for resizing an image was to capture the image data, then draw it to an offscreen html Canvas. from there you can resize/rotate etc, then grab the image as jpg or png using canvas.toDataUrl(). You can then post that data to your backend.

1 Like

I am also using canvas to resize image.
But I am just curios if using GraphicsMagick is a better option or not.
If can’t use GraphicsMagick then I will only using canvas.

Just wondering what if I want to rotate image with ionic 2. What library would you recommend?