Hlavní navigace

Odpověď na názor

Odpovídáte na názor ke článku Jak hromadně zmenšit fotky.

  • 10. 3. 2008 17:04

    PMD (neregistrovaný)

    Pokud se nebojíte Photoshopu ve Wine, tak tady je můj skriptík v Javascriptu. Zmenšuje to po kouskách a pokaždé trochu doostří. Dá se pustit na jeden obrázek, volat z dávky atp. Dělá to ještě pár "administrativních" věcí navíc. Omluvte kvalitu kódu, je Javascript moc neumím;)

    #target photoshop
    app.bringToFront();
    app.displayDialogs = DialogModes.NO;

    var resampleMethod = ResampleMethod­.BICUBIC;
    var destMode = ChangeMode.RGB;
    var destBitDepth = BitsPerChannel­Type.EIGHT;
    var destProfile = "sRGB IEC61966-2.1";

    var recipes1 = [["4300px", 20], ["2800px", 30], ["1300px", 20], ["800px", 10]];
    var recipes2 = [["3800px", 20], ["2300px", 30], ["1300px", 20], ["800px", 10]];
    var recipes3 = [["3300px", 20], ["2300px", 30], ["1300px", 20], ["800px", 10]];
    var recipes4 = [["2800px", 20], ["1800px", 30], ["1300px", 20], ["800px", 10]];
    var recipes5 = [["2300px", 20], ["1800px", 30], ["1300px", 20], ["800px", 10]];
    var recipes6 = [["1800px", 30], ["1300px", 40], ["800px", 10]];
    var recipes7 = [["1300px", 50], ["800px", 30]];
    var recipes8 = [["800px", 90]];
    var recipes9 = [];

    function selectRecipes(size) {
    var px = size;
    px.convert("px");
    var value = px.value;

    if (value > 4500)
    return recipes1;
    else if (value > 4000)
    return recipes2;
    else if (value > 3500)
    return recipes3;
    else if (value > 3000)
    return recipes4;
    else if (value > 2500)
    return recipes5;
    else if (value > 2000)
    return recipes6;
    else if (value > 1500)
    return recipes7;
    else if (value > 800)
    return recipes8;
    else
    return recipes9;
    }

    function resizeWidth(doc, width) {
    doc.resizeIma­ge(width, null, null, resampleMethod);
    }

    function resizeHeight(doc, height) {
    doc.resizeIma­ge(null, height, null, resampleMethod);
    }

    function shrink(doc, recipes, resizer) {
    var layer = doc.artLayers[0];

    for (i = 0; i < recipes.length; i++) {
    var size = recipes[i][0];
    resizer(doc, size);
    var amount = recipes[i][1];
    layer.applyUn­SharpMask(amou­nt, 1, 0);
    }
    }

    function main(doc) {
    doc.flatten();
    doc.resizeIma­ge(null, null, 300, ResampleMethod­.NONE);
    doc.changeMode(des­tMode);
    doc.convertPro­file(destProfi­le, Intent.PERCEPTUAL, true, false);
    doc.bitsPerChannel = destBitDepth;

    if (doc.height <= doc.width) {
    shrink(doc, selectRecipes(doc­.width), resizeWidth);
    } else {
    shrink(doc, selectRecipes(doc­.height), resizeHeight);
    }
    }

    if (app.documents­.length != 0) {
    main(app.acti­veDocument);
    } else {
    alert("No open document!");
    }