Highcharts PhantomJS export SVG as base64 - svg

I have a question regarding generating an SVG instead of an PNG serverside using PhantomJS. I have PhantomJS running as a server and am POSTing JSON to it (http://www.highcharts.com/docs/export-module/render-charts-serverside). I would like to receive an SVG represented as a BASE64 result stream. I am running in some problems however.
I tried both the following requests, but the base64 result would always represent a png file:
{"infile":".......", "type":"image/svg+xml"}
And:
{"infile":".......", "type":"svg"}
I do however get a valid svg file when I use the outfile parameter:
{"infile":".......", "type":"svg", "outfile":"anActualSVG.svg"}
This writes a file to disk, which is not what I am looking for.
Does anyone have some suggestions?
Thanks!

Related

Decrypting Image Headers for WebP, JPEG XL, HEIF, AVIF image formats using Python

I want to decode and understand the structure of various latest image formats (namely WebP, JPEG XL, HEIF and AVIF) and compare header information with respect to image data to see which format is header information heavy with respect to image data. I was wondering how I can do this using Python.
Is there a simple way to decode various image file formats of the same image in either HEX or Binary and learn how much of the file contents is the image data and how much else is the header information? Better yet, is there a way to learn the breakdown of header information for various file formats??
So far I got to a point where I got a file to open in binary mode (Below is the sample code I have for the AVIF test image) but I'm not sure how I can decrypt, read and understand the structure. Googling around, I found some information for JPEG format (like the information shown on this page for JPEG https://yasoob.me/posts/understanding-and-writing-jpeg-decoder-in-python/) but none for WebP, HEIF, and AVIF on how I can read the binary format.
image = 'test.avif'
with open(image, 'rb') as image_file:
content = image_file.read()
Content
I wish to know how exactly can we extract the header information from the images while compression.

Image resolution low after converting pdf to image using GraphicsMagick for NodeJS

I'm trying to convert pdf into image using gm package and i just can't understand how should i adjust the output resolution.
If i'm doing like this:
gm(`${sourcePath}[0]`)
.setFormat('jpg')
.stream()
.pipe(writeStream);
The output quality here is very low, so i'm trying to use density(594, 842)
like this:
gm(`${sourcePath}[0]`)
.setFormat('jpg')
.quality(100)
.density(595, 842)
.stream()
.pipe(writeStream);
but doing this the image looks very starchy.
Can anyone please point me what should i do in order to receive the
output image close as possible to the pdf source using the npm package?
Or maybe recommend me about a different library that i can use for converting pdf to image (before ocr)

Binary data from mongodb gets corrupted

When I upload a photo it converts to base64 and then when I send to mongodb using Mongoose it saves as Binary. But when I call the same picture back from the database it returns as Buffer array. After converting to base64 it returns as a base64 string but completely different from the original base64. The new base64 is unable to be rendered in browser because it has been corrupted.
Below are pictures of the different strings
This is the initial base64
This is the Buffer array
This is the corrupted base64 after converting from the buffer array using Buffer.from(avatar).toString('base64').
Please note that I appended to it "data:image/png;base64," before rendering in the browser and it still did not render.
Please can someone tell me what I am doing wrong?
the best solution is convert to png or jpg file and upload only path and save image to folder.
Here is how I solved it.
I converted from binary to utf8 instead of to base64.
There is a huge difference bewteen
Buffer.from(binary_data, 'binary').toString('utf8')
and
Buffer.from(binary_data, 'binary').toString('base64')

Is it possible to get actual cropped PNG from Croppie instead of the base64 encoding?

I am using Croppie to crop an image and it is giving me base64 which creates 413 error while sending it on server for large images, so I need proper image file. I tried to find converting it(base64) as a image file locally at client side but didn't get expected way for conversion using javascript/jquery.
Please guide me.

express-fileupload:get check size in express js

I am using this package
to upload the image into server ,i want to check the file size before upload but express-fileupload doesn't give any information about it
console.log(req.files.image); it returns only the name,data ,and image type
Assuming the name of your file in your HTML file is image, req.files.image.data.length will give you the buffer length in bytes. See this Node.js. API Documentation for more details. You can then do the math to convert the number of bytes into any thing you want.
This will allow you to get the actual number of bytes independent of filetype and doesn't require using the mv function. So you can use this on any file type not just images.
Hopefully this helps!
I think only way to get image info using express-fileupload is using mv function to move image on server then using image-size to get width and height

Resources