cancel
Showing results for 
Search instead for 
Did you mean: 

overwrite files with scripts

bplatt
Champ in-the-making
Champ in-the-making
I need to resize, adjust and overwrite uploaded photos. 

I cannot find documentation on how to save the image back over itself.

I have so far

var newImage = document.transformImage("image/jpeg","-normalize -resize 1024x768",  document.parent);

This gives me an error about the file existing.
3 REPLIES 3

jbarmash
Champ in-the-making
Champ in-the-making
I'd suggest you rename the old image, write the new image, and then delete the renamed old image (rename old image instead of deleting in case something goes wrong and you need to retry).

bplatt
Champ in-the-making
Champ in-the-making
So I have gotten this far:

// "-normalize -resize 1024x768",

var strOrigName = document.properties.name;
var tmpName = "resized_" + document.properties.name;
document.properties.name =  tmpName;
var rImage=document.transformImage("image/jpeg","-normalize -resize 1024x768",  document.parent);
if (rImage){
document.properties.name =  strOrigName;
   document.save();
   //document.remove();
}

The documentation does not seem to give any way to access specific known docs.  So I can rename and save the new resizedimage, but cannot figure out how to delete the old file nor can I figure out how to rename the new document.  I am very familiar with javascript and maybe I am too clouded by regular web scripting to see how this works.

The errors I get state nodeRef is required, but I cannot find anyway to obtain a nodeRef.

jbarmash
Champ in-the-making
Champ in-the-making
I just tried deleting nodes and it works, using remove() or document.removeNode.  I did get exceptions throwin in the UI, but that is because after you delete "document", it tries to come back to properties sheet, but the document no longer exists. so you need to make sure you run the script not from the document itself, but from some other place.  find the node you want using search.