Loading...
Logo
Processing Forum

Filenames...

in Programming Questions  •  1 year ago  
hello all'

is it possible in Processing to sequentially images being saved from Processing ie is something like this possible:

img.save(MonaLisa _n

where n is a number from an array or increases incrementally?

I'm not seeing any clues in the reference and being a bit rusty (haven't coded since 1990!) would appreciate a helping hand!
J

Replies(13)

Re: Filenames...

1 year ago
Do you know

http://processing.org/reference/saveFrame_.html

But sure you can also img.save and increment the name
img.save("MonaLisa_"+trim(str(n));
not tested

http://processing.org/reference/PImage_save_.html
aha,,

thanks Chris! 
String$ came back to me form ZX81 days - my next question was going to be how would you load a certain number image i guess something like:

PImage myImage = loadImage("MonaLisa_"+trim(str(n));

I will look into str uses in reference - all will become clear I am sure...
thanks!

J

Re: Filenames...

1 year ago

All this has to be done in a loop to change n - either a for loop or by draw()

For loading though you need an Array - see reference

in your code myImage would just be overwritten

better
myImage[n]=loadImage ......;
this was dawning on me - tho i couldn't see what was going on I guessed I might need an array as my variables weren't working.

basically I'm trying to save a jpg then reopen it and then save it then reopen it ad infinitum.

I'm trying to create a sequence of gradually compressed jpegs to the point where the image decays from sharp to over compressed...

the array thingy should nail it!

J

Re: Filenames...

1 year ago
No need for the trim() on the str(), I think. You might also want to look at the nf() function, if you used saveFrame().

Re: Filenames...

1 year ago
(Answering last reply to Chrisir, this Comment thingy is impractical...)

No need for an array for your task, not even for saveFrame(): you just need a global counter, to be used in save().
img.save("bla-" + nf(counter, 3) + ".jpg");
and reload as:
img = loadImage("bla-" + nf(counter, 3) + ".jpg");
a counter++ and you can repeat the process.
Your experiment could be more effective if we could control the Jpeg quality but Processing doesn't allow this directly.

Re: Filenames...

1 year ago
No need for array that I thought too


aha a counter,

you guys are a great help thanks! 

I tried something like:

img.save("bla-" + n + ".jpg")

last night but Processing didn't seem to like adding strings to variables to renumber files sequentially. Then again I am a total noob so I probably had a typo in there.

re controlling jpeg compression there are some javascript doohickeys here:


if you're interested - but frankly calling JS at this point is too tricky for me to contemplate.

I'm hoping that continually opening and saving the same jpeg will actually recursively gradually compress an image to big blocks it may take 10k iterations or more but I'm interested to see what happens. 

most likely bugger all! :-D

J

Re: Filenames...

1 year ago
righty this is wot I got:

int counter=0;

void draw() {
  PImage img = loadImage("source-" + nf(counter, 3) + ".jpg");
  counter = counter + 1;
  img.save("source-" + nf(counter, 3) + ".jpg");
    
}

{
loop();
}

it creates a sequence of JPEGS but is each successive JPEG an open and save of the previous? I think it is but can one of you experts let me know if I got it right?! Will be much appreciated!  
J

Re: Filenames...

1 year ago
I've checked for differences in file 000 and file 200 by overlaying and blending with difference in PShop - doesn't look like my idea will generate any results - looks like I'll have to mug up on how to call in that JS routine :-/
J

Re: Filenames...

1 year ago
He is saving without compressing the image further (i dunno how to do, Probably a Lib?)

You could make small changes in the img to see if the loop is working 

Or see

http://processing.org/learning/topics/blur.html

etc.
good idea  re blur. 

will have a head scratch and see if I can unpick the JS routine or have a look at a Lib - but I have a feeling that I may have hit a dea end. I don't want to force the compression too much - I'm testing a hypothesis that every time a jpeg is renamed it under goes some kind of recompression when saved - I  may have to throw out the hypothesis.

J

Re: Filenames...

1 year ago
Woah, lot of strange things/misconceptions above... First, there is no JavaScript in the link you mention... But at least indeed, that's the code you need to lower the quality of your Jpeg image.

Now, I thought you wanted to keep all the intermediary images to do some effect, compare each step, or something like that. But with 10K iterations, that's a lot to keep. And, no, using different file names isn't useful.

" Processing didn't seem to like adding strings to variables to renumber files sequentially."
Wrong, there is no problem with that, but you don't tell us what went wrong in your experiment.

Side note: what is this loop(); in your code above?

Anyway, I think you over-complicated your experiment...
Here is a simpler one:
Copy code
  1. PImage original;
  2. final String PATH = "H:/Temp/Test.jpg";
  3.  
  4. void setup()
  5. {
  6.   size(1024, 768);
  7.  
  8.   original = loadImage("H:/PhiLhoSoft/images/foret_0003_1024.jpg");
  9.   original.save(PATH);
  10. }
  11.  
  12. void draw()
  13. {
  14.   PImage test = loadImage(PATH);
  15.   image(test, 0, 0);
  16.   text(frameCount, 10, 30);
  17.   test.save(PATH);
  18. }
I used absolute paths because I haven't saved the sketch, so the save location is in temporary files.
After 600 iterations, I don't see a very visible degradation, perhaps we need more, or as you did, to compare the files by differencing them in an image editor.
I suppose Jpeg images are saved with relatively high quality, so indeed you might need the code you saw to reduce the quality and see more pronounced artifacts.