分享

【转】ps标注源码

 天使之翼 ` 2019-05-15

// v1.0

function setScaleF(a){return function(b){return b/a}}function formatValueWithUnits(a,b,c){return c=c||"",""+a+c+b}function drawLine(a,b){var c=makePoint(a),d=makePoint(b),e=new SubPathInfo;e.closed=!1,e.operation=ShapeOperation.SHAPEXOR,e.entireSubPath=[c,d];var f=doc.pathItems.add("Line",[e]);f.strokePath(ToolType.PENCIL),f.remove()}function makePoint(a){for(var b=0;b<a.length;b++)a[b]=scale(a[b]);var c=new PathPointInfo;return c.anchor=a,c.leftDirection=a,c.rightDirection=a,c.kind=PointKind.CORNERPOINT,c}function pickTool(a){var b=charIDToTypeID("slct"),c=new ActionDescriptor,d=charIDToTypeID("null"),e=new ActionReference,f=stringIDToTypeID(a);e.putClass(f),c.putReference(d,e),executeAction(b,c,DialogModes.NO)}function setPenToolSize(a){var b=charIDToTypeID("slct"),c=new ActionDescriptor,d=charIDToTypeID("null"),e=new ActionReference,f=charIDToTypeID("PcTl");e.putClass(f),c.putReference(d,e),executeAction(b,c,DialogModes.NO);var g=charIDToTypeID("setd"),h=new ActionDescriptor,i=new ActionReference,j=charIDToTypeID("Brsh"),k=charIDToTypeID("Ordn"),l=charIDToTypeID("Trgt");i.putEnumerated(j,k,l),h.putReference(d,i);var m=charIDToTypeID("T   "),n=stringIDToTypeID("masterDiameter"),o=charIDToTypeID("#Pxl");c.putUnitDouble(n,o,a),h.putObject(m,j,c),executeAction(g,h,DialogModes.NO)}var doc=null,docIsExist=!1,selBounds=null,selIsExist=!1,store={activeLayer:null,rulerUnits:app.preferences.rulerUnits,typeUnits:app.preferences.typeUnits,font:null};app.preferences.rulerUnits=Units.PIXELS,app.preferences.typeUnits=TypeUnits.POINTS;try{doc=app.activeDocument,docIsExist=!0}catch(e){alert("Size Mark Script: no document\nUse File \u2192 New... to create one")}if(docIsExist)try{selBounds=doc.selection.bounds,selIsExist=!0}catch(e){alert("Size Mark Script: no selection\nUse Rectangular Marquee Tool (M) to create one")}if(docIsExist&&selIsExist){var halfMark=3,txtMargin=5,baseRes=72,decimPlaces=1,layerOpacity=65,docRes=doc.resolution,scaleRatio=docRes/baseRes,scale=setScaleF(scaleRatio),realUnits="px",scaledUnits="pt",charThinSpace="\u200a",selX1=selBounds[0].value,selX2=selBounds[2].value-1,selY1=selBounds[1].value,selY2=selBounds[3].value-1,selWidth=selX2-selX1,selHeight=selY2-selY1,val=0,txtLayerPos=[0,0],layerNamePrefix="MSRMNT",txtJ11n=Justification.LEFT;store.activeLayer=doc.activeLayer,doc.selection.deselect();var markLayer=doc.artLayers.add();setPenToolSize(1),selWidth>selHeight?(drawLine([selX1,selY1],[selX2,selY1]),drawLine([selX1,selY1-halfMark],[selX1,selY1+halfMark]),drawLine([selX2,selY1-halfMark],[selX2,selY1+halfMark]),layerNamePrefix="W",val=selWidth+1,txtLayerPos=[selX1+val/2,selY1-txtMargin],txtJ11n=Justification.CENTER):(drawLine([selX1,selY1],[selX1,selY2]),drawLine([selX1-halfMark,selY1],[selX1+halfMark,selY1]),drawLine([selX1-halfMark,selY2],[selX1+halfMark,selY2]),layerNamePrefix="H",val=selHeight+1,txtLayerPos=[selX1+txtMargin,selY1+val/2+4],txtJ11n=Justification.LEFT),markLayer.opacity=85;var txtLayer=doc.artLayers.add();txtLayer.kind=LayerKind.TEXT;var txtLayerItem=txtLayer.textItem;store.font=txtLayerItem.font,txtLayerItem.font="ArialMT",txtLayerItem.autoKerning=AutoKernType.OPTICAL,txtLayerItem.position=txtLayerPos,txtLayerItem.justification=txtJ11n,txtLayerItem.color=app.foregroundColor;var label="";baseRes!==docRes&&(label=formatValueWithUnits(scale(val).toFixed(decimPlaces),scaledUnits,charThinSpace)+" / "),label+=formatValueWithUnits(val,realUnits,charThinSpace),txtLayerItem.contents=label;var finishLayer=txtLayer.merge();finishLayer.name=layerNamePrefix+val,txtLayer=doc.artLayers.add(),txtLayer.kind=LayerKind.TEXT,txtLayerItem=txtLayer.textItem,txtLayerItem.font=store.font,txtLayer.merge(),finishLayer.move(store.activeLayer,ElementPlacement.PLACEBEFORE),finishLayer.opacity=layerOpacity,app.preferences.rulerUnits=store.rulerUnits,app.preferences.typeUnits=store.typeUnits,pickTool("marqueeRectTool")}


//Size Marks.jsx

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多