node-module to convert multi images tiff into multipages tiff - javascript

I want to merge multiple tiff images into one single tiff image using nodejs/javascript.
How to get single tiff having multi-pages for multiple tiff images in nodejs?
Is there any way to convert pdf of multiple pages into one tiff image in nodejs?

I struggled to find a solution to this as well and what I learned is that there isn't really a great option. Anything you do, no matter what, will require semi-annoying dependency installations depending on where you are deploying your solution. Also, they will all use some variation of imagemagick or graphicsmagick or libtiff or some other variant I haven't seen yet.
I made a quick setup that will programmatically download image magick binaries and setup correct environment variables and paths to run imagemagick's convert cli tool programmatically through a node.js spawn command. You can check out the full repo here:
https://github.com/wolfejw86/tiff-images-playground
The short answer is this though:
get image magick or libtiff binaries into your environment
ensure your running node.js process has access to those
call the binary directly with child_process's .spawn method or use something like the gm npm module - https://www.npmjs.com/package/gm - that depends on the binary you need.

Related

How to detect the file type if it's an excel file in JavaScript on the web?

I am using the FileReader() API to read files on the browser, I want to render something on the screen conditionally based on the file the user uploads:
JSON.
CSV.
Excel.
How can I detect if the file uploaded is an excel file? Do you use libraries for that or is there a genius way we can detect that blindly without going through all the chances?
Running out of space in comments, so I'll add an answer. Files will usually have an extension, on both Windows and Linux, but if you don't want to rely on that you can just try parsing the file in each of the formats to find the one that succeeds.
JSON use JSON.parse()
Excel see this question for .xlsx or this one for .xls, or use one of the many NPM packages
CSV the format is pretty simple, but there are gotchas for commas in the values. Some of the libraries are pretty efficient at streaming large files, so probably worth using an NPM package again

How to programatically reduce PDF Size in Node/Javascript

I have seen other solutions for other languages (Object C/Swift/ Java) and was wondering if there was an established method/package to reduce the size of PDF's using Node. Currently I use PDFKIT to generate PDFs in my backend but I need their file sizes to be about half (currently 1mb -> 500kb) or smaller ideally. I have looked through NPM and several forums but have not found a way to compress PDFs with javascript. I notice that countless Online-PDF-Compression websites exist and they are able to compress my 1mb PDF to 55kb. So I'm sure there are solutions that exist for Javascript/Node
I faced a similar issue and after going through several forums, the solution I came up was to use shrinkpdf and to execute a shell command in node js I used shelljs library which has the following syntax,
const shell = require('shelljs')
shell.exec('./path_to_your_file')
All you have to do it execute the shell script given on the link.

Is there an npm module to modify a pdf file in node.js?

I'm building a node.js app on Bluemix that should take a pdf file as request and then grey out (blank) some part of the pdf file. And also here the pdf file is the same for all, and the area we need to blank out will be fixed. So can anybody suggest an npm module that can perform this kind of functionality?
Yes I guess the most common used library is pdf-lib. Take a look at the official page.
I suggest you to try HummusPDF. Specifically take a look at the Hummus - Modification page, that explains how to edit existing PDF documents. In your case you could try to use the feature that allows to draw shapes.
Please try Aspose.PDF Cloud SDK for Node.js available at GitHub and npm. It provides API methods for a wide range of document processing operations; including creation, manipulation, conversion and rendering of Pdf documents in the cloud. You can use Redaction Annotation to grey out the required PDF area.
P.S: I work with Aspose as Support Developer

Nodejs create a PNG image with text inside

I'm trying to create a new PNG file to serve back to clients via HTTP (as a response type image/png)
The new file is created by concatenating 3 base PNG files and adding a custom text in the middle of the image.
Problem is, there no built-in library in nodejs to do this. I spent a couple of hours searching and to my surprise, there is no pure JS library to do this. The closest thing is node-pngjs but it lacks the ability to add text. I understand that the text part is complicated since it's somewhat dependent on the OS (fonts installed, DLLs to interface with said fonts, etc).
There are other node modules that are wrappers around imageMagick (gm) and GTK (canvas) but unfortunately imageMagick is 155MB of binaries, and to use canvas you need to compile from source, install python and VS 2010 C++ Express Edition and it does not work on the lastest version of GTK.
The best I got right now is to write an .NET assembly and use it from inside node via edge.js, but that will require both Windows OS and .NET framework on the server.
Again, the complicated part here is adding the text inside the image.
Any suggestion on how to get this working without a sh**load of external dependencies?
Yes you are correct, the Node.js support for image processing libraries is weak, most are the wrappers of some CLI application.
The solution that I would use involves PhantomJS which has the canvas and svg support, you could use these features. It's lighter than the other options and does not require external applications to be installed. http://phantomjs.org/quick-start.html

Image sharing on deployd

I've recently begun experimenting with Deployd. It is (kind of) similar to meteor.
This may be amateurish question, but what happens if my collection consists of images?
How will I upload it to MongoDB # deployd dashboard?
I created a module for deployd to upload files (images included).
https://github.com/NicolasRitouet/dpd-fileupload
It lets you store the files in a local folder and in a collection to query them.
The only real way to use the Collection Resource Type to do this right now would be to base64 encode the image and store it as a string property. There are some limitations and performance issues with base64 images though. Alternatively, #dallonf has created an Amazon S3 resource to make it easy to integrate deployd apps with S3. http://docs.deployd.com/docs/using-modules/official/s3.md
There have been a lot of requests for storing binary files in collections, and hopefully someone (core committer or otherwise) can work on this after the forthcoming deployd release which includes significant improvements to the module API. This Github issue is worth watching: https://github.com/deployd/deployd/issues/106

Categories