cancel
Showing results for 
Search instead for 
Did you mean: 

run linux system command from rule

stegbth
Champ in-the-making
Champ in-the-making
Hi,

when a user uploads a jpeg, this should get resized to 1024x768 to save space.
On the fileserver this was done with imagemagick, like "find pictures/ -type -f -iname '*.jpg' -exec mogrify -verbose -resize 1024x768 {} \;

What's is the simpliest way to resize the picture within alfresco Share?
I found in alfresco "data Dictonary/scripts" i can locate JavaScript Scripts, but as far as i understand there i cant run a systemcommand?

Or how should this js look like?

best regards
Thomas
8 REPLIES 8

hello_wrold
Champ in-the-making
Champ in-the-making
I would set up a folder rule that executes a tiny (javascript-)script each time a new image is uploaded. Alfresco has a built-in transformation service that can do all the resizing.  The code would be something like

document.transformImage("image/jpeg", "-resize 1024x768");
document.save();

where 'document' is the special variable that points to the document the folder rule is currently working with. There is an example at

https://wiki.alfresco.com/wiki/JavaScript_API_Cookbook#Create_Document_and_Transform_it


HTH

stegbth
Champ in-the-making
Champ in-the-making
Hi HTH,

thank you very much for your answer.
when i check the preexisting script "append_copyright.js"
this consist only of


if (document.hasPermission("Write"))
{
   if (document.mimetype == "text/plain")
   {
      document.content += "\r\n\r\nCopyright (C) 2006";
   }
   else if (document.mimetype == "text/html")
   {
      document.content += "<br><br><small>Copyright &copy; 2006</small>";
   }
}


so is your code not enough?

It's not enough, i tested, it, but i don't understand why.

best regards
Thomas

stegbth
Champ in-the-making
Champ in-the-making
Hi Hth,

i found https://forums.alfresco.com/forum/developer-discussions/alfresco-explorer-development/overwrite-file...
There is nearly exactly the js i need. it transformes and create.
only the delete at the end is uncommented.

i will test this script, thank you very much

best regards
Thomas

stegbth
Champ in-the-making
Champ in-the-making
Hi,

i am having some difficulties to understand the script from https://forums.alfresco.com/forum/developer-discussions/alfresco-explorer-development/overwrite-file...

It is running, but leave at the end: picture.jpg AND resized_picture.jpg.
When add document.remove() i get at the end
resized_resized_resized_resized_resized….picture.jpg.

as the rule is "connected" to the folder the script get started over and over, right?
So best solution would be to check document.properties.name if it starts with resized_, right?

best regards
Thomas

hello_wrold
Champ in-the-making
Champ in-the-making
I run the script, but that recursion you describe could due to your folder rule. If you set up the rule firing on 'new or modified content' the rule is going to fire on the temporary file.

By the way: if you're tinkering with java script in Alfresco, I highly recommend installing the JavaScript console from add-ons.

stegbth
Champ in-the-making
Champ in-the-making
Hi Hth,

yes, the rule is setup to fire on new or modified content.
When should the rule else get fired?
So best solution would be to check the if the filename starts with resized_ and exit the script, right?

best regards
Thomas

stegbth
Champ in-the-making
Champ in-the-making
Hi HTH,

when should the rule else fired?

how can i check, if the content of the variable strOrigName starts not with resized_ ?

best regards
Thomas

stegbth
Champ in-the-making
Champ in-the-making
Hi,

i modified the script like this:


var strOrigName = document.properties.name;
if (!strOrigName.startsWith('resized')){
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();
}
}


but with this script nothing happens. Is the first "if (!strOrigName … )' correct?

greetz
Thomas