Skip to content

Instantly share code, notes, and snippets.

@dshster
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dshster/eafb2cb7a4b0055a2314 to your computer and use it in GitHub Desktop.
Save dshster/eafb2cb7a4b0055a2314 to your computer and use it in GitHub Desktop.
Скрипт уменьшения изображений в Adobe Photoshop для публикации в веб
#target photoshop
app.bringToFront();
$.localize = true;
var target_size = 999;
var tmp_target_size = target_size * 2;
var inputFolder = Folder.selectDialog("Выберите папку с фотографиями");
var outputFolder = Folder.selectDialog("Выберите папку для сохранения");
var fileList = inputFolder.getFiles();
for (var i = 0; i < fileList.length; i++) {
if (
fileList[i] instanceof File
&&
false === fileList[i].hidden
) {
open(fileList[i]);
resize();
app.activeDocument.bitsPerChannel = BitsPerChannelType.EIGHT;
ConvertTosRGBProfile();
SaveAsJPEG(createUniqueName(app.activeDocument.name), 9);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
function SaveAsJPEG(inFileName, inQuality) {
var jpegOptions = new JPEGSaveOptions();
var outfile = new File(outputFolder + '/' + inFileName);
jpegOptions.quality = inQuality;
app.activeDocument.saveAs(outfile, jpegOptions, true);
}
function sharpenLayer(docRef, opacity_value) {
docRef.selection.selectAll();
docRef.selection.copy();
var layerRef = docRef.artLayers.add();
docRef.paste();
layerRef.applySharpen();
layerRef.opacity = opacity_value;
docRef.flatten();
return true;
}
function resize() {
if (0 != app.documents.length) {
var docRef = app.activeDocument;
docRef.flatten();
var src_width = docRef.width;
var src_height = docRef.height;
/* первый этап */
if (src_width > src_height) {
var new_width = tmp_target_size;
var new_height = Math.floor(tmp_target_size * (src_height / src_width));
} else {
var new_width = Math.floor(tmp_target_size * (src_width / src_height));
var new_height = tmp_target_size;
}
docRef.resizeImage(new_width, new_height, docRef.resolution, ResampleMethod.BICUBIC);
sharpenLayer(docRef, 70);
/* второй этап */
if (src_width > src_height) {
var new_width = target_size;
var new_height = Math.floor(target_size * (src_height / src_width));
} else {
var new_width = Math.floor(target_size * (src_width / src_height));
var new_height = target_size;
}
docRef.resizeImage(new_width, new_height, docRef.resolution, ResampleMethod.BICUBIC);
sharpenLayer(docRef, 50);
}
}
function createUniqueName(inFileName) {
var prefix = "_resized";
var lastDot = inFileName.toString().lastIndexOf(".");
var extension = inFileName.toString().substr(lastDot + 1, inFileName.toString().length - lastDot);
return inFileName.toString().substr(0, lastDot) + prefix + '.' + extension;
}
function ConvertTosRGBProfile() {
app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true);
}
@dshster
Copy link
Author

dshster commented Jun 12, 2014

Скачиваем скрипт в любимую папочку, открываем Photoshop, изображение, в меню выбираем
File -> Scripts -> Browse... и выбираем мой скрипт который запускается автоматически.

В 3 строчке var target_size = 999; указывается размер широкой стороны изображения, которое получится в итоге. Рекомендую не больше половины размера исходного изображения (всё же скрипт предназначен для уменьшения изображения под веб)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment