We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is it possible to open an image file, and get the size in pixels of the image as you load it? I have a bunch of photos with similar, but not identical, dimensions. I need to transform and rotate the images which is currently failing with some lovely screen displays!!
Answers
Yes. If you have your image loaded, like so:
Then you can directly access the size of that image in pixels:
Brilliant - how did I miss that and thank you. I've just found exiftool which may also come in handy for another task
Hello again - I can see how img.width and img.height will work for what I need, but I'm making a basic mistake that I can't see the answer to. I'm loading the imag and showing the sizes exactly as tfGuy44 shows above, but when I use it in size() I get an error message "place size() function inside settings() rather than setup()" I've read the usage notes but can't see how I can call settings() as that seems to only specify max size as screen size.
Check the fourth example:
https://processing.org/reference/settings_.html
In your case:
If you are working with different images, you can either resize your images or resize the sketch window.
Kf
But if you look at the code he's doing this in a loop. Which isn't going to work, I don't think.
I'd ditch the screen display and load and modify the images using createGraphics or something.
(Actually i'd probably use imagemagick)
koogs and kfrajer - thank you for your info here. The loop comment is correct, I've copied the code from a few exampls and I'm making what I need work really well, if the images are all the same size. The info is in a loop, as you've picked up and I did wonder about ditching screen display. I need to remove excess from the code and print it an look again. Koogs comment - imagemagick and creategraphics?? I'll look at that and thanks everyone for your help.
koogs is correct, you can use a PGraphics and save it directly. The concept is the following:
Kf
(imagemagick is a non-Processing solution, it's a command line program for manipulating graphics.)
Btw @koogs,is it available in Windows? Not sure if the OP is using Win or Linux... I only have exp using imageMagick in Linux.
Kf
It is, but it's not as nice because DOS.
Hello again- sorry for delay getting back - I have MacBook and win 7 PC. I'm going to have a good look at the pgraphics tools - thank you :)
Hi everyone - thank you for your help - the pgraphics looks like it's taking me the right way - One question - how do I add text on to the images that I'm working with in the graphics tools? I've tried text and guessed at pg.text neither seemed to do anything (no output, no errors).. i see that text writes to the screen, and now by using the pgraphics tools I'm no longer writing to the screen so nothing for the text to go on..
Why not just resize the image to fit the window instead of the other way around? If all the images are the same size and always will be, you can just hardcode the window size.
Don't forget to do all the other text things as well. Setting the font and colours etc. In the graphics context I mean, using pg.
Ha - it might not show so much on this post but the images are not the same size. With same size images I've been able to knock out text marked pictures quite easily. (I take all the pictures in portrait) and have used the transform and rotate okay. The references to pgraphics are definitely helping, so I'm loading the images, manipulating them in processing and writing them back - they are now all going back in correct orientation with correct size but no text on :( I've found the detailed image class reference material and now trying to work out how to use it. Ive found this but not sure how to use it public void text(int num, float x, float y, float z)
koogs - this s where I may have confused myself. I think I've just understood that pg is almost like an entire sub language inside processing and needs things setting up the right way - please see my comment above - is the public void etc.. the way i need to approach this? (btw processing is awesome)
Ive been doing some searching and have found this forum post. I'll see if this is along he lines kooks was mentioning earlier https://forum.processing.org/one/topic/text-in-combination-with-pgraphics.html Its on my to do list for tomorrow :)
Post what you have now and we'll have a look.
What that's doing is applying methods to that instance of the graphics object. Without the instance name it is applying them to the graphics instance that is the main sketch, ie the screen. Pretty much everything you can do to the screen you can do to an offscreen buffer...
thank you for your help everyone - here is my current sketch
Edit post, highlight code, press Ctrl-o to format
Leave a blank line between the text and the code.
oops - sorry about that.
ok, i don't have the images or the csv file or the font... so this is an example
basically, everything you need to draw your image needs to be applied to the pgraphics.
Thank you loads for this help - I'll tidy up my work and get this working. I'll post back my finished work and a copy of the csv and hopefully it will help someone else
Many thanks everyone heres the file I created - makes new images approx. one per second