Giter Club home page Giter Club logo

Comments (14)

oliver-moran avatar oliver-moran commented on September 23, 2024

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.

dataxa avatar dataxa commented on September 23, 2024

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.

oliver-moran avatar oliver-moran commented on September 23, 2024

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.

Input:
lenna

Output:
cr_lenna

from jimp.

dataxa avatar dataxa commented on September 23, 2024

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.

oliver-moran avatar oliver-moran commented on September 23, 2024

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.

dataxa avatar dataxa commented on September 23, 2024

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.

oliver-moran avatar oliver-moran commented on September 23, 2024

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.

dataxa avatar dataxa commented on September 23, 2024

Is there an easy way to convert EXIF to JIMP manageable format?

from jimp.

oliver-moran avatar oliver-moran commented on September 23, 2024

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.

dataxa avatar dataxa commented on September 23, 2024

Thanks for help - much appreciated. Love the non-dependable plugin.

from jimp.

oliver-moran avatar oliver-moran commented on September 23, 2024

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.

pankajdx48 avatar pankajdx48 commented on September 23, 2024

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.

CapnSpellcheck avatar CapnSpellcheck commented on September 23, 2024

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.

CapnSpellcheck avatar CapnSpellcheck commented on September 23, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.