This question already has answers here:
Opening images on NodeJS and finding out width/height
(3 answers)
Closed 9 years ago.
I am using express 3 to make a http server which uploads the image in a designated folder but I am not able to get the image resolution in the req object .
I tried looking in req.files and req.files.images and req.files.headers but I could not find that information .
How can I get the resoultion of the uploaded image .
See solution here: Opening images on NodeJS and finding out width/height
var im = require('imagemagick');
im.identify(req.files.images.path, function(err, features){
if (err) throw err
console.log(features)
// { format: 'JPEG', width: 3904, height: 2622, depth: 8 }
})
Make sure you have imagemagick included and installed in your project.
Related
Evening Everyone,
I have started doing some research for an application i want to write using the electron framework. I have figured out how to display what i want to the user with the exception of the icons. There is a part of the application where the user can type a path and it will list the files in that path, i would like to pull the icon from the files so its displayed just like it would be in the windows file explorer. This is where i have been running into a roadblock and I'm looking for some guidance.
Is there a method in nodejs that would allow me to provide a file path and in return get a image back i can pass to HTML? Im new to nodejs so i figured i would ask and see if anyone knew of an easy way.
There is icon-extractor
you can use it like this to extract any app icon from the system , but it must be an**".exe"** file.
var iconExtractor = require('icon-extractor');
var fs= require('fs');
iconExtractor.emitter.on('icon', function(data){
console.log('Here is my context: ' + data.Context);
console.log('Here is the path it was for: ' + data.Path);
var icon = data.Base64ImageData;
fs.writeFile('img.png', icon, 'base64', (err) => {
console.log(err);
});
});
iconExtractor.getIcon('ANY_TEXT','PAHT_TO_APP.exe');
If you are using electron, you might run into a lot of issues. For me no other package worked than this one:
Windows Powershell Icon Extractor
This question already has answers here:
File uploading with Express 4.0: req.files undefined
(13 answers)
Closed 6 years ago.
I'm triying to upload an excel file with postman and save it in to a folder with node.js fs:
var file = req.body.file;
fs.writeFile("public/myExcelFile.xlsx", file, function(err) {
if(err) {
res.json(err);
} else {
res.json("The file was saved!");
}
});
But when I try to open the file after upload it is corrupt or empty,
can you tell me pls what im doing wrong?
In the future I have to upload another files like .docx or .csv so I want to know what is the best way to save these files, it's better save files in database(I´m using Sql server) as a blob ? or save the file in a folder and save the path in database?
You might want to try using node.js streams. I believe it's best to only save the path in the database.
I am using Express to serve resized images. Which Node.js package should be used to resize the image? I've seen a lot of packages that change the image and save it as a file, but I need to change the image and write data to response. Example:
package.compress('/path/to/image.png',
{width: 100px, height: 100px},
function(result) {
res.end(result);
});
I chosen thumb-express (https://www.npmjs.com/package/thumb-express). This is what I need.
This question already has answers here:
How to relink/delink image URLs to point to the full image?
(2 answers)
Closed 7 years ago.
i want to make Greasemonkey script to replace text in html like this:
<img src="http://example.com/image.jpg" data-gifsrc="http://example.com/image.gif">
to
<img src="http://example.com/image.gif">
in website thechive.com
please help me, thanks.
While I cannot find the data-gifsrc attribute on the mentioned website, youi cannot assume the JQuery would be present and available for Greasemonkey.
// attribute name
var attrName='data-gifsrc';
// list all images
var imgs=document.getElementsByTagName("img");
// loop every images
for(var i=0;i<imgs.length;i++) {
// check for attribute
if(imgs[i].attributes[attrName]) {
// set image source
imgs[i].src=imgs[i].attributes[attrName].value;
// remove attribute
imgs[i].attributes.removeNamedItem(attrName);
}
}
I'm writing simple app that downloads JPEGs images from Flickr API, and then process them.
All I want to do, is to pick 4 random pixels from each image and save the HEX values.
Is it possible at all? I read a lot of graphicmagick documentation, but can't find a way to do this.
Whats the best way to decode JPEG and get this values? I tried a few plugins but neither can do this by default...
Take care!
https://npmjs.org/package/get-pixels seems nice for that:
var getPixels = require("get-pixels")
getPixels("lena.png", function(err, pixels) {
if(err) {
console.log("Bad image path")
return
}
console.log("got pixels", pixels.shape)
})