1

J'ai un script qui tente de:Photoshop/InDesign CS5 Script: erreur de conversion de taille d'image utilise trop de mémoire?

  • numériser un document InDesign pour toutes les images
  • envoyer toutes les images à Photoshop via le   BridgeTalk   objet
  • Redimensionner toutes les images à 600px largeur (maintien de l'aspect ratio mathématiquement)
  • exporter toutes les images de Photoshop dans un nouveau dossier

Il semble que je devrais ajuster le DPI de chaque image par programme, car Photoshop plante avant même qu'une image ne soit redimensionnée. L'erreur indique que la mémoire temporaire est surchargé par ce script, et je suppose qu'il a quelque chose à voir avec la qualité d'image et/ou la taille ... Voici le message d'erreur:

erreur Photoshop générale a eu lieu . Cette fonctionnalité peut ne pas être disponible dans cette version de Photoshop.
Erreur dans la ligne 1:
Impossible de terminer la commande car les disques de travail sont pleins.




Voici le code correspondant qui transforme la taille de l'image:

function resaveInPS(imagePaths, imagesFolder) 
{ 
    /* 
    * NOTE: no single-line comments are allowed in this function, because it is not read line-by-line by BridgeTalk, but as a single String; 
    *  only multi-line comments will work, because they are terminated at each end 
    */ 

    BridgeTalk.bringToFront("photoshop"); /* switch view from InDesign to Photoshop */ 

    app.displayDialogs = DialogModes.NO; /* Photoshop statement, prevents status alerts from interrupting */ 

    var imagePath = ""; 
    var fileName = ""; 
    var largerImage = ""; 

    for(var i = 0; i < imagePaths.length; i++) 
    { 
     imagePath = imagePaths[i].fullName; 
     fileName = imagePaths[i].name; 
     largerImage = fileName.substr(0, fileName.length - 4); /* getting rid of the file extension: Photoshop will handle the file extension */ 

     var photoshopDoc = ""; 
     photoshopDoc = app.open(new File(imagePath)); 

     var currentWidth = photoshopDoc.width; /* in inches */ 
     var currentHeight = photoshopDoc.height; /* in inches */ 

     currentWidth.convert("px"); /* now in pixels */ 
     currentHeight.convert("px"); /* now in pixels */ 

     var newWidth = 600; /* defining the desired exported image width here */ 
     var ratio = newWidth/currentWidth; 
     var newHeight = ratio * currentHeight; /* maintaining aspect ratio of the resized image's height here */ 

     alert("The currentHeight is " + currentHeight + ".\n\nThe ratio is " + ratio + ".\n\nThe newHeight is " + newHeight + "."); 

     photoshopDoc.resizeImage(newHeight, newWidth); /* (height, width) */ 
     photoshopDoc.resizeCanvas(newHeight, newWidth); /* (height, width) */ 

     var saveOptions = new TiffSaveOptions(); /* handling the file extension here */ 
     photoshopDoc.saveAs(new File(imagesFolder + "/" + largerImage), saveOptions); /* saving the new image in the folder here, with the file extension */ 
     photoshopDoc.close(SaveOptions.DONOTSAVECHANGES); /* close the Photoshop document without saving */ 
     app.purge(PurgeTarget.ALLCACHES); /* clears the clipboard, history, and undo cache in Photoshop; Note: does NOT delete the temporary files! */ 

    } /* end of for loop */ 

    app.displayDialogs = DialogModes.ALL; /* resume normal dialogs after saving the file and closing the document */ 
    app.purge(PurgeTarget.ALLCACHES); /* clears the clipboard, history and undo cache in Photoshop; Note: does NOT delete the temporary files! */ 

} // end of function ResaveInPS 


NOTE  -  Mon utilisation de la déclaration   app.purge(PurgeTarget.ALLCACHES)   ne semble pas avoir beaucoup d'effet, comme l'erreur est toujours en cours ...

+1

Vous n'avez défini aucun type d'unité sur 'newWidth' et' newHeight'. Êtes-vous sûr de ne pas essayer de redimensionner à 600 pouces? –

+0

Ah! J'ai totalement raté ça, merci @Mark. Je supposais à tort que la contrainte de type implicite s'appliquerait aux valeurs unitaires, mais bien sûr, elle ne le peut pas car "pixel" n'est pas un type Javascript par défaut. –

+1

Me rappelle une histoire que j'ai eu de seconde main. Une société présentait une nouvelle table traçante à grande vitesse avec alimentation en rouleau lors d'un salon professionnel. Ils utilisaient un dessin d'architecture pour la démonstration, et quelqu'un a oublié de régler le facteur de mise à l'échelle - il a commencé à imprimer à grande échelle, tirant du papier loin à travers le sol. –

Répondre

2

Donc, je supposais à tort que la contrainte de type s'appliquerait aux valeurs unitaires, mais bien sûr, ce ne serait pas parce que « pixel » est pas un défaut de type Javascript.

Sans application   new UnitValue  -  var ratio, le rapport est contraint de taper   Number   (bien que   currentWidth  est instancié avec une unité de type "pixel"). De même,   var newWidth   reste un type   Number tel quel.


Voici le code corrigé, en commençant par la ligne   var currentWidth   et se terminant par   resizeCanvas  :

 var currentWidth = photoshopDoc.width; /* in inches */ 
     var currentHeight = photoshopDoc.height; /* in inches */ 

     currentWidth.convert("px"); /* now in pixels */ 
     currentHeight.convert("px"); /* now in pixels */ 


     var newWidth = new UnitValue(600, "px"); /* defining the desired exported image width here */ 
     var ratio = new UnitValue(newWidth/currentWidth, "px"); 
     var newHeight = new UnitValue(ratio * currentHeight, "px"); /* maintaining aspect ratio of the resized image's height here */ 

     /*alert("The currentHeight is " + currentHeight + ".\n\nThe ratio is " + ratio + ".\n\nThe newHeight is " + newHeight + ".");*/ 

     photoshopDoc.resizeImage(newWidth, newHeight); /* (width, height) */ 
     photoshopDoc.resizeCanvas(newWidth, newHeight); /* (width, height) */ 


Aussi, j'ai les paramètres des méthodes   resizeImage   et   resizeCanvas   en arrière! C'est l'ordre correct pour les deux:   (width, height).


- merci à @Mark de m'avoir indiqué dans la bonne direction.