2017-05-28 5 views
0

イメージが保存されているフォルダが複数あります。Photoshop CCバッチアクションTinyPNGプラグイン

フォルダ構造は次のようになります、

Folder structure

私はソースフォルダとして「全商品」フォルダを取るバッチコマンドを作成したいtinyPNG Photoshopのプラグイン(https://tinypng.com/)とストアを使用していますすべての製品 - >製品X - >圧縮画像

このようなすべての製品の圧縮ファイルは可能ですか?

+0

あなたがこれまでに試してみましたか? (スクリプトの面で) – treintje

+0

画像としてではなくテキストとしてフォルダ構造を投稿してください。テキストは簡単にコピーして、テストに使用する可能性のある回答者になることができますが、画像はできません。他の人はすべてのタイプを再入力しなければなりません... – aschipfl

+0

@aschipflテキストとして投稿しましたが、それがどのように見えるべきかを見ることは困難でした。 –

答えて

0

私は実際には別のものに行きました:このスクリプトはフォルダを開き、jpeg、png、tifイメージをすべて取得し、白いキャンバス(ウーマンコマースや他のeコマースシステムに最適)で四角形にサイズ変更し、圧縮しますtinyPNGプラグインを使用して既存のファイルを上書きすると、その場でフォルダを作成する必要はなく、同じフォルダに画像が保存されるので、元の画像をすべてコピーして上書きするだけで済みます。

スクリプトを使用すると、選択したサイズ(この場合は2000x2000)でポートレートモードまたはランドスケープモードの画像を四角形(画像のサイズを変更しキャンバスを拡張することで動作)に変換できます。店舗システムで。左側には、あなたは、元のものを見ることができ、右リサイズと圧縮1上:enter image description here enter image description here

使用する方法:あなたがtinyPNGプラグインを購入したり、独自の輸出のロジックを使用する必要がまず第一に(たとえば標準Photoshop Web Export)を開き、コードを.jsxファイルとして保存し、Photoshop - > Presets - > Scriptsフォルダに保存します。これでFile - > Automateセクション(PSを再起動しない場合)に新しいオプションが表示されます。一度にフォルダ内のすべての画像(サブフォルダを含む)を一括してサイズ変更して圧縮するには、まずPhotoshopでルートフォルダの画像を開き、「画像を四角形に圧縮...」ボタンを押すとダイアログが表示されますあなたはフォルダを選択する。今では、圧縮率のための今すぐ(画像の多くでかなり長い時間がかかることができます)

を実行してみましょう:enter image description here

TinyPNGは本当に画像の圧縮で良い仕事をしていません。ここで

最終スクリプト:

/* 

// Get images from a folder recursively resize to square and compress with tinyPNG 
// Copyright (c) 2017 Alex Gogl 

<javascriptresource> 
<menu>automate</menu> 
<name>$$$/JavaScripts/ToSquareCompress/Menu=Resize images to Square and Compress...</name> 
<eventid>7b078a04-ba43-4214-8eda-4026a5d2bd33</eventid> 
</javascriptresource> 

*/ 

function compressFile(file, percentage) { 

    // Open the file without dialogs like Adobe Camera Raw 
    var opener = new ActionDescriptor(); 
    opener.putPath(charIDToTypeID("null"), file); 
    executeAction(charIDToTypeID("Opn "), opener, DialogModes.NO); 

    // Select the opened document 
    var document = app.activeDocument; 

    // Change the color space to RGB if needed 
    if (document.mode == DocumentMode.INDEXEDCOLOR) { 
     document.changeMode(ChangeMode.RGB); 
    } 

    // Switch to 8 bit RGB if the image is 16 bit 
    if (document.bitsPerChannel == BitsPerChannelType.SIXTEEN) { 
     convertBitDepth(8); 
    } 

    // Choose the scale percentage 
    if (percentage === undefined || percentage < 10 || percentage > 100) { 
     percentage = 100; 
    } 

    //-----------START RESIZE LOGIC----------- 
    // these are our values for the END RESULT width and height (in pixels) of our image 
    var fWidth = 2000; 
    var fHeight = 2000; 

    // do the resizing. if height > width (portrait-mode) resize based on height. otherwise, resize based on width. if height equals width do nothing 
    //ResamlpleMethod set to BICUBICSHARPER due to most images being resized to a smaller resolution 
    if (document.height > document.width) { 
     document.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBICSHARPER); 
    } 
    else { 
     document.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBICSHARPER); 
    } 

    // Makes the default background white 
    var white = new SolidColor(); 
    white.rgb.hexValue = "FFFFFF"; 
    app.backgroundColor = white; 

    // Convert the canvas size as informed above for the END RESULT 
    app.activeDocument.resizeCanvas(UnitValue(fWidth,"px"),UnitValue(fHeight,"px")); 
    //-----------END RESIZE LOGIC----------- 

    // Compress the document 
    var tinify = new ActionDescriptor(); 
    tinify.putPath(charIDToTypeID("In "), file); /* Overwrite original! */ 
    tinify.putUnitDouble(charIDToTypeID("Scl "), charIDToTypeID("#Prc"), percentage); 
    tinify.putEnumerated(charIDToTypeID("FlTy"), charIDToTypeID("tyFT"), charIDToTypeID("tyJP")); /* Force JPEG */ 

    var compress = new ActionDescriptor(); 
    compress.putObject(charIDToTypeID("Usng"), charIDToTypeID("tinY"), tinify); 
    executeAction(charIDToTypeID("Expr"), compress, DialogModes.NO); 

    document.close(SaveOptions.DONOTSAVECHANGES); 
} 

function convertBitDepth(bitdepth) { 
    var id1 = charIDToTypeID("CnvM"); 
    var convert = new ActionDescriptor(); 
    var id2 = charIDToTypeID("Dpth"); 
    convert.putInteger(id2, bitdepth); 
    executeAction(id1, convert, DialogModes.NO); 
} 

function compressFolder(folder) { 
    // Recursively open files in the given folder 
    var children = folder.getFiles(); 
    for (var i = 0; i < children.length; i++) { 
     var child = children[i]; 
     if (child instanceof Folder) { 
      compressFolder(child); 
     } else { 
      /* Only attempt to compress PNG,JPG,TIFF files. */ 
      if ((child.name.slice(-5).toLowerCase() == ".jpeg")||(child.name.slice(-4).toLowerCase() == ".jpg" || ".png" || ".tif")) { 
       compressFile(child); 
      } 
     } 
    } 
} 

if (confirm("Warning. You are about to compress all JPEG files in the chosen folder. This cannot be undone.\n\rAre you sure you want to continue?")) { 
    try { 
     // Let user select a folder 
     compressFolder(Folder.selectDialog("Choose a folder with JPEG/PNG/TIF images to compress with TinyJPG")); 
     alert("All JPEG/PNG/TIF files compressed."); 
    } catch(error) { 
     alert("Error while processing: " + error); 
    } 
} 

注:(sunbrellaのような)オブジェクト、すなわち画像中央に整列されていないがある場合は、最終画像はまた、中央に整列されることはありません誰かが私が聞いてうれしくなることを修正するためのアイデアがあれば。

出典:Photoshop JavaScript to resize image and canvas to specific (not square) sizes

https://tinypng.com/photoshop/support#tips-tricks

関連する問題