Copy link to clipboard
Copied
Hello All,
I'm trying to demonstrate the degradation of jpeg's over multiple recompressions.
My planned approach is;
Open image;
Save image as new file at compression rate x;
Open the newly compressed file;
Loop;
I would like to run the script so I get 1000 images in a folder each x% of the previous image.
Does that make any sense?
If anyone has any ideas to help me i'd very much appreciate it.
tia
fess
Sorry, I had misunderstood.
While (as far as I can tell) for Photoshop-jpgs it’s irrelevant if they are saved after a change or saved as I have adapted the Script.
A selection on the top left is inverted to cause a save-able change.
// saves jpg multiple times;
// be advised: this closes the open file without saving and overwrites existing jpgs of the same name without prompting.
// 2011, use it at your own risk;
#target photoshop;
// set the number of saves;
var theNumber = 50;
if (app.documents.len
...Copy link to clipboard
Copied
You could try this:
// saves jpg into same folder;
// be advised: this closes the open file without saving and overwrites existing jpgs of the same name without prompting.
// 2011, use it at your own risk;
#target photoshop;
// set the number of saves;
var theNumber = 50;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path}
catch (e) {var docPath = "~/Desktop"};
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg as a copy:
for (var m = 0; m < theNumber; m++) {
var thePath = docPath+"/"+basename+"_"+bufferNumberWithZeros(m + 1, 3)+".jpg";
thedoc.saveAs((new File(thePath)),jpegOptions,true);
thedoc.close(SaveOptions.DONOTSAVECHANGES);
var thedoc = app.open(File(thePath));
};
//that’s it; thanks to xbytor;
};
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
var theNumberString = String(number);
for (var o = 0; o < (places - String(number).length); o++) {
theNumberString = String("0" + theNumberString)
};
return theNumberString
};
Copy link to clipboard
Copied
I forgot to mention: you can set the number of copies by changing
var theNumber = 50;
and the jpg-quality with
jpegOptions.quality = 9;
Copy link to clipboard
Copied
Firstly can I thank you, I wasn't expecting someone to write the code out for me at all. I've been sat at a machine in my office all day trying to figure this out and have only just discovered your post.
I started another thread;
http://forums.adobe.com/thread/777102?tstart=0
which shows my lack of intelligence somewhat as I completely forgot about the edit stage of the process. Without it, it doesn't matter how many times the jpeg are opened they will not degrade.
I feel dead cheeky asking but any clues as to how I go about this?
Per chance do you have a paypal account or a favourite charity i could donate to as reward?
I appreciate your time and thank you for your help so far.
Copy link to clipboard
Copied
which shows my lack of intelligence somewhat as I completely forgot about the edit stage of the process. Without it, it doesn't matter how many times the jpeg are opened they will not degrade.
That is incorrect.
Edit: Sorry on my part; I guess you are right that a Close-Open-Save without changes will not degrade (as it does not actually save).
The Close-Open-Save As will degrade the image, as seen in these images (first generation jpg, 40th generation jpg; I did not test higher that that):
Copy link to clipboard
Copied
Sorry, I had misunderstood.
While (as far as I can tell) for Photoshop-jpgs it’s irrelevant if they are saved after a change or saved as I have adapted the Script.
A selection on the top left is inverted to cause a save-able change.
// saves jpg multiple times;
// be advised: this closes the open file without saving and overwrites existing jpgs of the same name without prompting.
// 2011, use it at your own risk;
#target photoshop;
// set the number of saves;
var theNumber = 50;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path
var thePath = docPath+"/"+basename+".jpg";
}
catch (e) {
var docPath = "~/Desktop";
var thePath = docPath+"/"+basename+".jpg";
};
// save as jpg if not a jpg yet;
if (docName.indexOf(".jpg") == -1) {
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg as a copy:
thedoc.saveAs((new File(thePath)),jpegOptions,true);
};
// close doc;
thedoc.close(SaveOptions.DONOTSAVECHANGES);
//save jpg as a copy:
for (var m = 0; m < theNumber; m++) {
File(thePath).copy(File(docPath+"/"+basename+"_"+bufferNumberWithZeros(m + 1, 3)+".jpg"));
var thePath = docPath+"/"+basename+"_"+bufferNumberWithZeros(m + 1, 3)+".jpg";
var thedoc = app.open(File(thePath));
// make change;
thedoc.selection.select([[0,0], [0,1], [1,1], [1,0]]);
thedoc.selection.invert();
// save;
thedoc.save();
thedoc.close(SaveOptions.DONOTSAVECHANGES);
};
//that’s it; thanks to xbytor;
};
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
var theNumberString = String(number);
for (var o = 0; o < (places - String(number).length); o++) {
theNumberString = String("0" + theNumberString)
};
return theNumberString
};
But if I remember correctly, in another thread concerning jpg-properties I have been made aware that it is in principle possible to only over-save the regions affected by a change and leave the rest unchanged; Photoshop does not handle jpgs that way, though.
Copy link to clipboard
Copied
You're very good, thank you for your time and effort. Is it sad that I find all this very interesting?
thxs
Copy link to clipboard
Copied
You don't need to make a selection, just invert the whole image twice (which gets back to the initial state, but marks the image dirty so it will save).
And if you do use a selection, you still need to invert twice to undo the damage.
Copy link to clipboard
Copied
I have found there is a limit to the degradation. Don't know if that is obvious to you or not but the images i've been playing with degrade to about the same extent your example image does. Interestingly it seems to occur around the 1500 cycled image. layered difference shows no difference at all between image 1550 and 5000... Any ideas as to why there is a limit to the degradation? Purely out of interest...
Copy link to clipboard
Copied
The pixels have converged to the DCT component quantization values -- so they shouldn't continue to degrade unless there's a bug in the math for the JPEG encoder.
Copy link to clipboard
Copied
This might seem like a silly question but where is the jpeg encoder stored? IS it per chance something i might be able to make adjustments to? I know it sounds daft. thxs
Copy link to clipboard
Copied
where is the jpeg encoder stored?
It is part of the code built into Photoshop.
Copy link to clipboard
Copied
You don't need to make a selection, just invert the whole image twice
Good point.
f3s5n3t, I trust you have been able to make those adjustments in the Script?
Copy link to clipboard
Copied
To tell the truth I haven't but I'll try work it out. I've extended my idea a little as well to see what certain adjustments do. E.g. I'm going to resize the image by 1px each way and back again to show how damaging resizing is. I think that different adjust options will give different degradation results. thxs for your help it is much appreciated.
Copy link to clipboard
Copied
Hi, sorry to be a pain.
I've had a go at adjusting the code;
// saves jpg multiple times;
// be advised: this closes the open file without saving and overwrites existing jpgs of the same name without prompting.
// 2011, use it at your own risk;
#target photoshop;
// set the number of saves;
var theNumber = 1000;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path
var thePath = docPath+"/"+basename+".jpg";
}
catch (e) {
var docPath = "~/Desktop";
var thePath = docPath+"/"+basename+".jpg";
};
// save as jpg if not a jpg yet;
if (docName.indexOf(".jpg") == -1) {
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 0;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg as a copy:
thedoc.saveAs((new File(thePath)),jpegOptions,true);
};
// close doc;
thedoc.close(SaveOptions.DONOTSAVECHANGES);
//save jpg as a copy:
for (var m = 0; m < theNumber; m++) {
File(thePath).copy(File(docPath+"/"+basename+"_"+bufferNumberWithZeros(m + 1, 3)+".jpg"));
var thePath = docPath+"/"+basename+"_"+bufferNumberWithZeros(m + 1, 3)+".jpg";
var thedoc = app.open(File(thePath));
// make change;
thedoc.selection.selectAll();
thedoc.selection.invert();
thedoc.selection.selectAll();
thedoc.selection.invert();
// save;
thedoc.save();
thedoc.close(SaveOptions.DONOTSAVECHANGES);
};
//that’s it; thanks to xbytor;
};
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
var theNumberString = String(number);
for (var o = 0; o < (places - String(number).length); o++) {
theNumberString = String("0" + theNumberString)
};
return theNumberString
};
When I run this code cs4 brings up a warning saying 'no pixels have been selected'. There is a check box to ignore future warnings. I assume it's my code?
I don't think I need the second selectAll but i'm not sure.
Am I being dense?
thanks once again
Copy link to clipboard
Copied
You inverted the selection, not the image.
You want to invert the image.
Copy link to clipboard
Copied
Try
// make No change;
thedoc.activeLayer.invert();
thedoc.activeLayer.invert();
Copy link to clipboard
Copied
Now that is interesting. That is effectively what I am trying to achieve but I want to take it to the extreme end of the scale. Is that using the script supplied?
Copy link to clipboard
Copied
I tried to run the scripts mentioned here but i could not detect any
changes after 5000 saves. Does anyone know what i might be doing wrong?
Copy link to clipboard
Copied
What i am trying to do is to save each file in the script at different, random quality:
I tried this script, but I could not detect any change:
// saves jpg multiple times;
// be advised: this closes the open file without saving and overwrites existing jpgs of the same name without prompting.
// 2011, use it at your own risk;
#target photoshop;
// set the number of saves;
var theNumber = 500;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path
var thePath = docPath+"/"+basename+".jpg";
}
catch (e) {
var docPath = "~/Desktop";
var thePath = docPath+"/"+basename+".jpg";
};
// save as jpg if not a jpg yet;
if (docName.indexOf(".jpg") == -1) {
// jpg options;
var randomNumber = Math.round(Math.random()*12)
for (var r = 0; r < theNumber; r++) {
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = randomNumber
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
};
//save jpg as a copy:
thedoc.saveAs((new File(thePath)),jpegOptions,true);
};
// close doc;
thedoc.close(SaveOptions.DONOTSAVECHANGES);
//save jpg as a copy:
for (var m = 0; m < theNumber; m++) {
File(thePath).copy(File(docPath+"/"+basename+"_"+bufferNumberWithZeros(m + 1, 3)+".jpg"));
var thePath = docPath+"/"+basename+"_"+bufferNumberWithZeros(m + 1, 3)+".jpg";
var thedoc = app.open(File(thePath));
// make change;
thedoc.selection.select([[0,0], [0,1], [1,1], [1,0]]);
thedoc.selection.invert();
// save;
thedoc.save();
thedoc.close(SaveOptions.DONOTSAVECHANGES);
};
//that’s it; thanks to xbytor;
};
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
var theNumberString = String(number);
for (var o = 0; o < (places - String(number).length); o++) {
theNumberString = String("0" + theNumberString)
};
return theNumberString
};
Anyone know how to do this?
Thanks
Find more inspiration, events, and resources on the new Adobe Community
Explore Now