论坛帮助 |
社区圈子 |
日历事件 |
2020-01-30, 17:52 | #1 | ||
|
|||
正式会员
等级: 四袋长老
|
ASSET_FOLDER_NAME = "links"; doc = app.activeDocument; var filename = doc.name.split(".")[0]; asset_folder = new Folder(doc.path + "/" + ASSET_FOLDER_NAME); var j = 0; if (asset_folder.exists || asset_folder.create()) { for (i = doc.placedItems.length - 1; i > -1; i--) { linked_file = doc.placedItems[i].file; collected_file = new File(asset_folder + "/" + linked_file.name); if (collected_file.fullName != linked_file.fullName) { linked_file.copy(collected_file); doc.placedItems[i].file = collected_file; } } for (i = doc.rasterItems.length - 1; i > -1; i--) { if (doc.rasterItems[i].embedded) { relink_image(doc.rasterItems[i]); } } } else { alert("Unable to create the assets folder."); } function relink_image(myFile) { try { linked_file = myFile.file; tempFpath = new File(asset_folder + "/" + linked_file.name); if (tempFpath.fullName != linked_file.fullName) { linked_file.copy(tempFpath) } } catch (err) { var myBBox = myFile.boundingBox; var myBounds = myFile.geometricBounds; var tempFpath = newFileName(); var newDocu = app.documents.add(); var newobj = myFile.duplicate(newDocu); newobj.position = Array(0, 0); if ((myBounds[2] - myBounds[0]) > (myBounds[1] - myBounds[3])) { if (myBBox[2] > myBBox[1]) { newobj.width = myBBox[2] - 0.1; newobj.height = myBBox[1] - 0.1; } else { newobj.height = myBBox[2] - 0.1; newobj.width = myBBox[1] - 0.1; } } else { if (myBBox[2] > myBBox[1]) { newobj.height = myBBox[2] - 0.1; newobj.width = myBBox[1] - 0.1; } else { newobj.width = myBBox[2] - 0.1; newobj.height = myBBox[1] - 0.1; } } var exportPSDOptions = new ExportOptionsPhotoshop(); exportPSDOptions.resolution = 300; exportPSDOptions.imageColorSpace = ImageColorSpace.CMYK; newDocu.exportFile(tempFpath, ExportType.PHOTOSHOP, exportPSDOptions); newDocu.close(SaveOptions.DONOTSAVECHANGES); } var replacedImage = doc.placedItems.add(); replacedImage.file = tempFpath; replacedImage.position = myFile.position; replacedImage.width = myFile.width; replacedImage.height = myFile.height; replacedImage.move(myFile, ElementPlacement.PLACEAFTER); myFile.remove(); } function newFileName() { var N = 1; var loopFlg = true; while (loopFlg) { var fileObj = new File(asset_folder + "/" + filename + "-" + N + ".psd"); N++; if (!fileObj.exists) { loopFlg = false; return fileObj; } } } |
||
2020-01-31, 18:01 | 只看该作者 #2 | ||
|
|||
正式会员
等级: 六袋长老
|
ASSET_FOLDER_NAME = "links"; doc = app.activeDocument; // 此处将选择的的链接图以及嵌入图放入refItems数组 var refItems=[]; for (i = doc.placedItems.length - 1; i > -1; i--) { if(doc.placedItems[i].selected){ refItems.push(doc.placedItems[i]); } } for (i = doc.rasterItems.length - 1; i > -1; i--) { if (doc.rasterItems[i].embedded&&doc.rasterItems[i].selected) { refItems.push(doc.rasterItems[i]); } } // var filename = doc.name.split(".")[0]; asset_folder = new Folder(doc.path + "/" + ASSET_FOLDER_NAME); if (asset_folder.exists || asset_folder.create()) { for (i = refItems.length - 1; i > -1; i--) { relink_image(refItems[i]); } } else { alert("Unable to create the assets folder."); } function relink_image(myFile) { try { linked_file = myFile.file; tempFpath = new File(asset_folder + "/" + linked_file.name); if (tempFpath.fullName != linked_file.fullName) { linked_file.copy(tempFpath); myFile.file=tempFpath; } } catch (err) { var myBBox = myFile.boundingBox; var myBounds = myFile.geometricBounds; var tempFpath = newFileName(); var newDocu = app.documents.add(); var newobj = myFile.duplicate(newDocu); var exportPSDOptions = new ExportOptionsPhotoshop(); exportPSDOptions.resolution = 300; exportPSDOptions.imageColorSpace = ImageColorSpace.CMYK; newDocu.exportFile(tempFpath, ExportType.PHOTOSHOP, exportPSDOptions); newDocu.close(SaveOptions.DONOTSAVECHANGES); } var replacedImage = doc.placedItems.add(); replacedImage.file = tempFpath; replacedImage.position = myFile.position; replacedImage.width = myFile.width; replacedImage.height = myFile.height; replacedImage.move(myFile, ElementPlacement.PLACEAFTER); myFile.remove(); } function newFileName() { var N = 1; var loopFlg = true; while (loopFlg) { var fileObj = new File(asset_folder + "/" + filename + "-" + N + ".psd"); N++; if (!fileObj.exists) { loopFlg = false; return fileObj; } } } |
||
右列会员因为此帖价值甚高向 木棉树下 表示感谢: |
yzx0120 (2020-01-31)
|
2020-01-31, 21:17 | 只看该作者 #3 | ||
|
|||
正式会员
等级: 四袋长老
|
引用:
|
||
2020-01-31, 23:09 | 只看该作者 #4 | ||
|
|||
正式会员
等级: 六袋长老
|
ASSET_FOLDER_NAME = "links"; doc = app.activeDocument; // 此处将选择的链接图以及嵌入图放入refItems数组 var refItems=[]; for (i = doc.placedItems.length - 1; i > -1; i--) { if(doc.placedItems[i].selected){ refItems.push(doc.placedItems[i]); } } for (i = doc.rasterItems.length - 1; i > -1; i--) { if (doc.rasterItems[i].embedded&&doc.rasterItems[i].selected) { refItems.push(doc.rasterItems[i]); } } // var filename = doc.name.split(".")[0]; asset_folder = new Folder(doc.path + "/" + ASSET_FOLDER_NAME); if (asset_folder.exists || asset_folder.create()) { for (i = refItems.length - 1; i > -1; i--) { relink_image(refItems[i]); } } else { alert("Unable to create the assets folder."); } function relink_image(myFile) { try { linked_file = myFile.file; tempFpath = new File(asset_folder + "/" + linked_file.name); if (tempFpath.fullName != linked_file.fullName) { linked_file.copy(tempFpath); myFile.file=tempFpath; } } catch (err) { var myBBox = myFile.boundingBox; var myBounds = myFile.geometricBounds; var tempFpath = newFileName(); var newDocu = app.documents.add(); var newobj = myFile.duplicate(newDocu); //还是把这一段加回去,对于缩放了的图像有用 newobj.position = Array(0, 0); if ((myBounds[2] - myBounds[0]) > (myBounds[1] - myBounds[3])) { if (myBBox[2] > myBBox[1]) { newobj.width = myBBox[2] - 0.1; newobj.height = myBBox[1] - 0.1; } else { newobj.height = myBBox[2] - 0.1; newobj.width = myBBox[1] - 0.1; } } else { if (myBBox[2] > myBBox[1]) { newobj.height = myBBox[2] - 0.1; newobj.width = myBBox[1] - 0.1; } else { newobj.width = myBBox[2] - 0.1; newobj.height = myBBox[1] - 0.1; } } var exportPSDOptions = new ExportOptionsPhotoshop(); exportPSDOptions.resolution = 300; exportPSDOptions.imageColorSpace = ImageColorSpace.CMYK; newDocu.exportFile(tempFpath, ExportType.PHOTOSHOP, exportPSDOptions); newDocu.close(SaveOptions.DONOTSAVECHANGES); } var replacedImage = doc.placedItems.add(); replacedImage.file = tempFpath; replacedImage.position = myFile.position; replacedImage.width = myFile.width; replacedImage.height = myFile.height; replacedImage.move(myFile, ElementPlacement.PLACEAFTER); myFile.remove(); } function newFileName() { var N = 1; var loopFlg = true; while (loopFlg) { var fileObj = new File(asset_folder + "/" + filename + "-" + N + ".psd"); N++; if (!fileObj.exists) { loopFlg = false; return fileObj; } } } //发现以下两种选项得到的嵌入图再导出是有差别的 |
||