gm icon indicating copy to clipboard operation
gm copied to clipboard

watermarking image using buffers instead of path to file ?

Open pociej opened this issue 11 years ago • 4 comments

hi im tring to watermark image using gm .
var imageGM = gm.subClass({ imageMagick: true }); imageGM() .subCommand('composite') . in ('-compose', 'Over', ./path_to_Watermark, './path_to_jpg) .write('./path_to_result', function(err){ console.log('done', err); });

using paths everything working ok. but : var imageGM = gm.subClass({ imageMagick: true }); var watermark = fs.readFileSync('/path_to_watermark); imageGM() .subCommand('composite') . in ('-compose', 'Over', watermark, './path_to_jpg) .write('./path_to_result', function(err){ console.log('done', err); });

i have :

done { [Error: Command failed: composite: unable to open image �PNG I20140801-16:08:15.026(2)? I20140801-16:08:15.027(2)? ': @ error/blob.c/OpenBlob/2587. I20140801-16:08:15.030(2)? composite: no decode delegate for this image format�PNG I20140801-16:08:15.030(2)? I20140801-16:08:15.030(2)? ' @ error/constitute.c/ReadImage/532. I20140801-16:08:15.030(2)? composite: missing an image filename `./path_to_watermark' @ error/composite.c/CompositeImageCommand/1616.

any ideas how to solve it? same issue when im trying to pass buffer for image which i want watermark. Also question, is it possible to write to buffer not to the path ?

regards and thanks for response. G.P.

pociej avatar Aug 01 '14 14:08 pociej

ooh I want to know if this is possible too! limit all those expensive io operations to a minimum :+1:

koraysels avatar Sep 21 '15 11:09 koraysels

I'd love to know if this was possible as well.

sops21 avatar Mar 13 '16 03:03 sops21

I haven't figured out how to do it with both an image and the watermark as buffers, but I have figured out how to keep the image as a buffer:

    gm(imageBuffer)
        .composite('./logo_path.png')
        .geometry(geometry)
        .gravity('SouthEast')
        .dissolve(this.options.opacity)
        .toBuffer(function (err, buffer) {
          next(err, buffer, 'image/jpeg');
        });
    };

Check out the code in this great library for more info.

gferrin avatar May 07 '16 17:05 gferrin

PLEASE !!! I want it too. It's gonna be very useful when work with complex or multiple composite like Displacement technique.

The reason is I use serverless (Lambda) which is cannot write file into directory (can but not a long term solution) and I have to stream buffer output to S3 first then return as URL for use with composite function and Displacement technique need at lease 5 compose for the end-result.

So it's work but it consume many resource especially run time of the service.

ThePongBRIKL avatar Jun 24 '22 08:06 ThePongBRIKL