简体   繁体   English

我有一个脚本来调整图像大小。 无论如何让它输出5张图像?

[英]I have a script to resize an image. Is there anyway to have it output 5 images?

doc = app.activeDocument;  

// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 1313;
var fHeight = 1750;

// do the resizing.  if height > width (portrait-mode) resize based on height.  otherwise, resize based on width
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

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

// 2012, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PERCENT;
myDocument.resizeCanvas(myDocument.width + 40, myDocument.height + 40, AnchorPosition.MIDDLECENTER)
app.preferences.rulerUnits = originalRulerUnits;
};

// our web export options
var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;

var newName = 'test'+doc.name+'.jpg';

doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);

I want to be able to generate 5 images with 5 different sizes with the same script.我希望能够使用相同的脚本生成具有 5 个不同大小的 5 个图像。 Is it just as simple as repeating my code multiple times, or do i need to reset some variables in between?是否就像多次重复我的代码一样简单,还是我需要在两者之间重置一些变量?

When I try just duplicating my code and changing the output file name and the sizes, it does it but my canvas size doesn't reset and change based off the current image size.当我尝试只是复制我的代码并更改输出文件名和大小时,它会这样做,但我的画布大小不会根据当前图像大小重置和更改。 It just keeps getting bigger.它只会越来越大。 Is there anyway to make the canvas size resize based on that current image size?无论如何,是否可以根据当前图像大小调整画布大小?

var sizes = [
{
    width: 1531,
    height: 1948
},
{
    width: 1303,
    height: 1954
},  
{
    width: 1066,
    height: 1909
}
 ];
doc = app.activeDocument;
// looping through all the sizes
for (var i = 0; i < sizes.length; i++)
{
    var cloneDoc = doc.duplicate(); // duplicates current document
    resizeAndSave(sizes[i].width, sizes[i].height); // passes width and height of sizes to function with your code
    cloneDoc.close(SaveOptions.DONOTSAVECHANGES); // closes the clone
    activeDocument = doc; // making sure that foremost document is the original doc
}

function resizeAndSave(fWidth, fHeight)
{
    //your code


// get a reference to the current (active) document and store it in a variable named "doc"




// these are our values for the END RESULT width and height (in pixels) of our image
//var fWidth = 1313;
//var fHeight = 1750;

// do the resizing.  if height > width (portrait-mode) resize based on height.  otherwise, resize based on width
activeDocument = doc;
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

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

// 2012, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PERCENT;

myDocument.resizeCanvas(myDocument.width + 40, myDocument.height + 40, AnchorPosition.MIDDLECENTER)

app.preferences.rulerUnits = originalRulerUnits;

};

// our web export options

var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;

var newName = 'test'+doc.name+'.jpg';

doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);

};

You need to reset or clone your original document in the beginning of the each loop.您需要在每个循环的开头重置或克隆原始文档。 I prefer cloning so I'd do something like this:我更喜欢克隆,所以我会做这样的事情:

// creating array of sizes
var sizes = [
{
    width: 313,
    height: 750
},
{
    width: 413,
    height: 150
}, ];

// looping through all the sizes
for (var i = 0; i < sizes.length; i++)
{
    var cloneDoc = doc.duplicate(); // duplicates current document
    resizeAndSave(sizes[i].width, sizes[i].height); // passes width and height of sizes to function with your code
    cloneDoc.close(SaveOptions.DONOTSAVECHANGES); // closes the clone
    activeDocument = doc; // making sure that foremost document is the original doc
}

function resizeAndSave(fWidth, fHeight)
{
    //your code
};
doc = app.activeDocument;
var savedState = app.activeDocument.activeHistoryState



// get a reference to the current (active) document and store it in a variable named "doc"




// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 1155;
var fHeight = 1471;

// do the resizing.  if height > width (portrait-mode) resize based on height.  otherwise, resize based on width
activeDocument = doc;
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

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

// 2012, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {
activeDocument = doc;
var cwidth = 2000;
var cheight = 2000;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

doc.resizeCanvas(cwidth, cheight, AnchorPosition.MIDDLECENTER)

app.preferences.rulerUnits = originalRulerUnits;

};

// our web export options

var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true

var newName = 'MIR'+doc.name +'-22_28'+'.jpg';

doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);

app.activeDocument.activeHistoryState = savedState

// these are our values for the END RESULT width and height (in pixels) of our image
var hWidth = 1141;
var hHeight = 1711;

// do the resizing.  if height > width (portrait-mode) resize based on height.  otherwise, resize based on width
activeDocument = doc;
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(hHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
    doc.resizeImage(UnitValue(hWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

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

// 2012, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {
activeDocument = doc;
var cwidth = 2000;
var cheight = 2000;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

doc.resizeCanvas(cwidth, cheight, AnchorPosition.MIDDLECENTER)

app.preferences.rulerUnits = originalRulerUnits;

};




// our web export options

var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;

var newName = 'MIR'+doc.name+'-24_36'+'.jpg';

doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);

app.activeDocument.activeHistoryState = savedState

// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 1058;
var fHeight = 1897;

// do the resizing.  if height > width (portrait-mode) resize based on height.  otherwise, resize based on width
activeDocument = doc;
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

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

// 2012, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {
activeDocument = doc;
var cwidth = 2000;
var cheight = 2000;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

doc.resizeCanvas(cwidth, cheight, AnchorPosition.MIDDLECENTER)

app.preferences.rulerUnits = originalRulerUnits;

};

// our web export options

var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;

var newName = 'MIR'+doc.name+'-24_43'+'.jpg';

doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);

app.activeDocument.activeHistoryState = savedState

// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 1360;
var fHeight = 1813;

// do the resizing.  if height > width (portrait-mode) resize based on height.  otherwise, resize based on width
activeDocument = doc;
if (doc.height > doc.width) {
    doc.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
    doc.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

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

// 2012, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {
activeDocument = doc;
var cwidth = 2000;
var cheight = 2000;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

doc.resizeCanvas(cwidth, cheight, AnchorPosition.MIDDLECENTER)

app.preferences.rulerUnits = originalRulerUnits;

};

// our web export options

var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;

var newName = 'MIR'+doc.name+'-30_40'+'.jpg';

doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);

app.activeDocument.activeHistoryState = savedState






// get a reference to the current (active) document and store it in a variable named "doc"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有9个小图像,当单击它们时,它们会在图像的较大版本中消失。 为什么不能在Browser(FF)中工作) - I have 9 small images that when clicked on, will fade in the bigger version of the image. Why wont work in Browser(FF)) 我的程序遇到错误。 错误是(我认为)正在改变图像的来源。 - I have come across an error with my program. The error is(I think) is changing the source of the image. javascript if else 语句不起作用。 即使我单击 twoStory 图像,它也会返回 singleStory。 我试过了!=和--- - javascript if else statement not working. It returns singleStory even if I click on the twoStory image. I have tried != and --- django rest 框架甚至显示上传图像的选项。 我在模型中有 imageField - django rest framework dosent even show the option to upload image. I do have imageField in models 我已经创建了一个简单的测试产品组合站点,但是图像会按调整大小移动 - I have created a simple test portfolio site, but the images move on resize 如何调整图像大小并保留在悬停时更改图像的能力 - How do I have images resize and retain the ability to have them change on hover 我有一个显示用户当前个人资料图像的图像元素。 我可以将该图像的 src 更改为文件输入中的图像吗? - I have an image element which displays the user's current profile image. Can I change the src of that image to the image inside the file input? 选择,然后使用jQuery调整具有一定比例的图像的大小 - Select, then resize images that have a certain ratio with jQuery firebase 存储图像必须有图像扩展名吗? - firebase storage images must i have image extension? 使用我当前使用的当前基本JQuery Image Gallery淡入图像 - Fading images in, with the current basic JQuery Image gallery i have used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM