I am a web developer who learning Swift language, I use Sharp library to convert the image (may several different format or just Buffer or ArryaBuffer)which get from remote url to any format like jpeg、png、webp before.
Now I want to do same thing in Swift but not find any library can do that like Sharp library in NodeJS do, so I have several question:
swift's http request the image's format is 'Data' type(no matter the image is which format), so whether i can convert the 'Data' type to any image format like jpeg or webp?
As I mention above, is there have any library like Sharp do in NodeJS that do same thing in Swift?
Many thanks!
Related
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
I am using next js for my web application, I am having a requirement where when a user uploads a pdf to my input, I will have to compress it (for example: 1MB). I searched here and there, but I am not able to get a prominent solution which can help me out! If I cannot compress a pdf, I would at least like to convert it into an Image, which I can use a library to convert? Can someone help me out on how to compress a PDF?
I would recommend:
Convert API
You have to pay, but it is a very easy and clean solution.
Alternatively, you can use:
Shrink PDF
...which is a wrapper for ghost script. more complex than the Convert API but easier than implementing ghost script yourself.
Or:
Ghost script
...You can implement it yourself if you wish.
Realistically, you are not going to be able to get a simple Node package where you can just do pdf.compress() and it is done well, unless it is a paid API.
I'm trying to create a DICOM viewer on my own, using only JavaScript and HTML5. I'm working on this project for the last few days and now I successfully parse all textual information I need and I can also correctly read and display uncompressed Grayscale and RGB images. Now I'm trying to display the so called "JPEG Lossless, Nonhierarchical, First- Order Prediction" type of image (in the DICOM file, it is enumarated with the Transfer Syntax Unique Identification: 1.2.840.10008.1.2.4.70) but I'm stuck. I want to read the Pixel Data of the image manually and build the image out of it. There is no actual information on how the bits are stored in the DICOM documentation and I really tried to find a good description of this kind of JPEG on the internet but with no success. Can you give me some advice on what exactly I have to read to solve my problem. Thank you all :)
Check this document, probably it leads you into the right direction
JPEG Lossless Codec
There are also some more links which may help:
dclunie jpeg sources
FYI, the Orthanc server for medical imaging already provides JPEG Lossless decompression through a REST API, which allows JavaScript/HTML5 applications to very easily display DICOM images in Web browsers. You can for instance have a look at the DWV plugin by Yves Martel.
I'm using a firebreath plugin and I am sending a raw binary image data from the plugin to JavaScript, but was not able to use this data as JavaScript did not recognize this. I later converted the raw image data to base64 format and used in JavaScript in which case I was able to draw the image but performance was hit as base64 conversion took nearly 100ms for each conversion.
Is there a way where in I can draw image directly from the raw image? I Basically have to improve performance.
rather than drawing it on a canvas, you could try putting a data URI in an image tag and sending it as a jpeg. Basically compress the image as much as you reasonably (for your application) can before you send it to javascript in order to minimize the amount you need to convert w/ base64. The only other way I could see it maybe working would be to use a websocket to talk to the plugin, which has its own problems.
I would like to convert a PNG or JPEG file to SVG. But I can't find anything on how to do it. The thing is I'm using devexpress reports to export it to image so the format can either be .jpg or .png. Now what I want is to convert it to SVG so that the image will still be in a better quality when passing it through Javascript and finally to Objective-C.
To explain a bit further.
I have a service which is coded using VB.net. This is server side; client side is Javascript and HTML: I'm using Phonegap to bridge Objective-C. What I'm doing really is creating a plugin which would pass a URL from Javascript and have Objective-C catch the url, then load it as an image and pass it to the ePOS SDK to print as an image.
What I noticed is that when I'm exporting the report using devexpress as a png, the image gets pixelated and a bit grainy because I'm scaling the image to make it bigger to fill the thermal paper (80mm). That's why instead of PNG I want it in SVG to preserve the quality of the image.
My question is where should I convert the image? On the server side or in Objective-C? And how will I do such a daunting task? I was thinking of doing it in Objective-C, but I think it is much better to convert it on the server side. What do you think?
Also is it possible to convert .png or .jpeg to a .svg file?
Thanks
You could do it on the server side with ImageMagick, but I think that since you'll be converting a bitmap image to vector graphics, you'll just get the same low-quality crap. Can you export your reports to PDF or another vector graphics format?