Comments (14)
Hi, @dataxa -
I think the issue is with this line:
image = image.crop((image.bitmap.width - 720 / 2) , 0 , 720 , 960);
There might be an issue of garbage-in-garbage-out.
You say the width of the copped image should be 720px but you crop the image starting at an x position that is 360px from the edge.
Did you mean this instead:
image = image.crop(image.bitmap.width - 720 , 0 , 720 , 960);
Let me know if this works. I'll add some kind of catch for this issue if that is what is going on.
from jimp.
I made very minimalistic sample and image still gets rotated:
var jimp = require("jimp");
var fs = require("fs");
var dir = "./src/lib/";
var images = fs.readdirSync(dir);
for(var i = 0 , l = images.length ; i < l ; i++){
jimp.read(dir + images[i] , function(err , image){
image.resize(jimp.AUTO , 960).write(dir + "CR_" + images[i]);
});
}
from jimp.
I had to modify your code slightly to get it to run:
var jimp = require("jimp");
var fs = require("fs");
var dir = "./src/lib/";
var images = fs.readdirSync(dir);
for(var i = 0 , l = images.length ; i < l ; i++){
var out = dir + "CR_" + images[i];
jimp.read(dir + images[i] , function(err , image){
image.resize(jimp.AUTO , 960).write(out);
});
}
I can't reproduce the issue.
from jimp.
There no relevant difference in the code. Here is the image I used: before
And this is the result image: after
Windows 10
Node v4.1.1
Jimp 0.2.13
from jimp.
Windows appears to be rotating the image even before I run the Jimp script. When I save this to my desktop, it is saved rotated.
Can you try opening the image in Windows Photo Viewer. Rotate it to the correct angle. Save it. Then try your resize script again in Jimp.
Edit: A more likely explanation is that Chrome (or however your are viewing it) is rotating it based on the EXIF data to appear upright whereas the image is actually 90 degrees rotated to begin with.
from jimp.
I tried to saved the image to my computer but it was not rotated like in your case.
I opened the JPEG file in photoshop (was not rotated) and saved it as JPG and then jimp script worked.
The JPEG originates from iPhone 6 - looks like JIMP cant handle it.
from jimp.
Yes, it's the EXIF data.
The image (i.e. pixel data) is rotated 90 degrees and it contains data saying it is rotated 90 degrees. See the "Orientation" field in the EXIF data here and compare with how the image is shown on that site:
http://regex.info/exif.cgi?imgurl=http%3A%2F%2Fwww.upload.ee%2Fimage%2F5311820%2Ftest.jpeg
It's an interesting question: whether to go with the pixel data or to "fix" the image automagically when Jimp reads it.
Fixing it automatically may cause confusion too because my Windows 7 machine shows the file rotated (i.e. doesn't read the EXIF, just shows the pixels) whereas your Windows 10 machine shows the file upright (i.e. does read the EXIF and rotates the pixels).
from jimp.
Is there an easy way to convert EXIF to JIMP manageable format?
from jimp.
EXIF isn't so much a different format. It's just additional information.
After mulling it over, I think I'll update Jimp read the EXIF data and respect it. If the information is there then the likelihood is that respecting it leads to the most desirable outcome.
I'll aim to release an update in the next couple of days.
from jimp.
Thanks for help - much appreciated. Love the non-dependable plugin.
from jimp.
Fixed in the latest release published to NPM last night. I just tested it on Windows using the test code and images from above. All fine. Thanks for spotting this.
from jimp.
I write the code like this but i am not able to crop the image .
var Jimp = require("jimp");
// open a file called "lenna.png"
var lenna = new Jimp("lenna.png", function () {
this.resize(220, 220) // resize
.write("lenna-small.png") // save
.quality(60) // set JPEG quality
.write("lenna-small.jpg") // save as JPEG
.greyscale() // set greyscale
.write("lena-small-bw.png") // save again
.crop(80, 100, 80, 50) // crop
.write("lena-small-bw-cropped.png"); // save again
});
from jimp.
Does it read the Exif data in the input by default? I discovered a problem where I'm uploading jpeg, but after processing in jimp, the output does not appear correct. Input jpeg has Exif orientation tag ≠ 1. P.S. Also I am noticing that image.bitmap.width
gives what should be the height - if it followed the Exif correctly then should it already be transformed? I'm thinking it should have been, because jimp should handle the Exif right at its initialization with the image.
from jimp.
@oliver-moran Looking at this commit 8bfdc9f for the Exif orientation, the line index.js calling exifRotate
I do not see in my installed version in node_modules. Instead I see this:
try { this._exif = EXIFParser.create(data).parse(); }
from jimp.
Related Issues (20)
- Error reading arraybuffer in production environment HOT 1
- Share some examples of how to use it.(Multi page tiff from multiple images)
- @jimp/png won't work with @jimp/custom HOT 1
- .brightness() method does not affect brightness
- Upgrade dependancy version of xml2js HOT 1
- Save to specific width and height in inches HOT 1
- Jimp.decoders is undefined in browser with webpack and typescript HOT 1
- ERR_PNPM_NO_MATCHING_VERSION No matching version found for @jimp/plugin-scale@^0.22.12
- zlib_bindings problem when used in Vite with Typescript HOT 1
- Do anyone can run jimp in latest reactjs project? HOT 1
- Unable to get it working in a Vue project. HOT 4
- [BUG] Error when using ES Modules with Jimp HOT 7
- Cannot load fonts in Web Worker HOT 1
- Japanese characters not able to write and render image
- Unable to install jimp library through npm bcz of vulnerabilities checks HOT 3
- Update phin version HOT 9
- Reading base64 image from a Buffer is slow HOT 2
- nvm sorry my bad
- problem with the file path when reading the file HOT 1
- autocrop cropEmpty: true HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jimp.