Sponsored link
Fireworks MX2004 Javascript サンプル 実例集
はじめに、ここのサンプルは個人的に使う分には自由にお使いください。
このworkは、クリエイティブ・コモンズ・ライセンスの下でライセンスされています。
私の設定だと、画質が荒くなるのでお好みで setExportOptionsを変えてください。
サンプル
ロゴを埋め込む
http://www.forest.impress.co.jp/article/2004/06/16/dogubako134.htmlによると
複数画像にロゴを貼り付けるときの道具「(Copyright!)PasteEngineがあるようですが、
Fireworksを使うと、近いことができます。
カレントのドキュメントに指定のロゴを埋め込む。
"file:///C|/tmp/xucker.gif"のファイルパスは変更してください。
var marginW=10; var marginH=10; var docW=fw.getDocumentDOM().width; var docH=fw.getDocumentDOM().height; fw.getDocumentDOM().importFile("file:///C|/tmp/xucker.gif", {left:0,right:0,top:0,bottom:0}, false); var layerW=fw.getDocumentDOM().getSelectionBounds().right-fw.getDocumentDOM().getSelectionBounds().left; var layerH=fw.getDocumentDOM().getSelectionBounds().bottom-fw.getDocumentDOM().getSelectionBounds().top; fw.getDocumentDOM().moveSelectionTo({x:docW-layerW-marginW, y:docH-layerH-marginH}, false, false); fw.exportDocumentAs(fw.getDocumentDOM(),null,fw.getDocumentDOM().exportOptions);
すべてのドキュメントを閉じる
var doc; var n=fw.documents.length; for(i=n-1;i>=0;i--){ fw.closeDocument(fw.documents[i],false); }
クリップボードをペースト
var doc; doc=fw.createDocument(); fw.getDocumentDOM().clipPaste("ask user", "vector");
現在のドキュメントを最適化して保存
fw.getDocumentDOM().setExportOptions({ animAutoCrop:true, animAutoDifference:true, applyScale:false, colorMode:"indexed", crop:false, cropBottom:0, cropLeft:0, cropRight:0, cropTop:0, ditherMode:"none", ditherPercent:0, exportFormat:"PNG", frameInfo:null, interlacedGIF:false, jpegQuality:80, jpegSelPreserveButtons:false, jpegSelPreserveText:true, jpegSelQuality:90, jpegSelQualityEnabled:false, jpegSmoothness:0, jpegSubsampling:0, localAdaptive:true, lossyGifAmount:33, macCreator:"", macFileType:"", name:"PNG8", numCustomEntries:16, numEntriesRequested:16, numGridEntries:6, optimized:true, paletteEntries:[ "#000000", "#ece9d8", "#0051e5", "#001499", "#aca899", "#de522f", "#f6f5f0", "#acc0f1", "#0066ff", "#0033cc", "#9e7264", "#ffffff", "#0058ee", "#cdcdbc", "#eeeee7", "#3399ff" ], paletteInfo:null, paletteMode:"adaptive", paletteTransparency:"none", percentScale:100, progressiveJPEG:false, savedAnimationRepeat:0, sorting:"none", useScale:true, webSnapAdaptive:true, webSnapTolerance:14, xSize:0, ySize:0 }); doc=fw.getDocumentDOM(); fw.exportDocumentAs(doc,null,null); fw.closeDocument(doc,false);
クリップボードを最適化して保存
var doc; doc=fw.createDocument(); fw.getDocumentDOM().clipPaste("ask user", "vector"); fw.getDocumentDOM().setExportOptions({ animAutoCrop:true, animAutoDifference:true, applyScale:false, colorMode:"indexed", crop:false, cropBottom:0, cropLeft:0, cropRight:0, cropTop:0, ditherMode:"none", ditherPercent:0, exportFormat:"PNG", frameInfo:null, interlacedGIF:false, jpegQuality:80, jpegSelPreserveButtons:false, jpegSelPreserveText:true, jpegSelQuality:90, jpegSelQualityEnabled:false, jpegSmoothness:0, jpegSubsampling:0, localAdaptive:true, lossyGifAmount:33, macCreator:"", macFileType:"", name:"PNG8", numCustomEntries:16, numEntriesRequested:16, numGridEntries:6, optimized:true, paletteEntries:[ "#000000", "#ece9d8", "#0051e5", "#001499", "#aca899", "#de522f", "#f6f5f0", "#acc0f1", "#0066ff", "#0033cc", "#9e7264", "#ffffff", "#0058ee", "#cdcdbc", "#eeeee7", "#3399ff" ], paletteInfo:null, paletteMode:"adaptive", paletteTransparency:"none", percentScale:100, progressiveJPEG:false, savedAnimationRepeat:0, sorting:"none", useScale:true, webSnapAdaptive:true, webSnapTolerance:14, xSize:0, ySize:0 }); fw.exportDocumentAs(doc,null,null); fw.closeDocument(doc,false);
クリップボードの画像を25%に縮小してPNGで保存
キャプチャー画像を保存するのに使っています。
//paste capture image var doc; doc=fw.createDocument(); fw.getDocumentDOM().clipPaste("ask user", "vector"); //resize fw.getDocumentDOM().scaleSelection(0.25, 0.25, "autoTrimImages transformAttributes"); fw.getDocumentDOM().clipCut(); fw.closeDocument(doc,false); //paste resized image doc=fw.createDocument(); fw.getDocumentDOM().clipPaste("ask user", "vector"); //export fw.getDocumentDOM().setExportOptions({ animAutoCrop:true, animAutoDifference:true, applyScale:false, colorMode:"indexed", crop:false, cropBottom:0, cropLeft:0, cropRight:0, cropTop:0, ditherMode:"none", ditherPercent:0, exportFormat:"PNG", frameInfo:null, interlacedGIF:false, jpegQuality:80, jpegSelPreserveButtons:false, jpegSelPreserveText:true, jpegSelQuality:90, jpegSelQualityEnabled:false, jpegSmoothness:0, jpegSubsampling:0, localAdaptive:true, lossyGifAmount:33, macCreator:"", macFileType:"", name:"PNG8", numCustomEntries:16, numEntriesRequested:16, numGridEntries:6, optimized:true, paletteEntries:[ "#000000", "#ece9d8", "#0051e5", "#001499", "#aca899", "#de522f", "#f6f5f0", "#acc0f1", "#0066ff", "#0033cc", "#9e7264", "#ffffff", "#0058ee", "#cdcdbc", "#eeeee7", "#3399ff" ], paletteInfo:null, paletteMode:"adaptive", paletteTransparency:"none", percentScale:100, progressiveJPEG:false, savedAnimationRepeat:0, sorting:"none", useScale:true, webSnapAdaptive:true, webSnapTolerance:14, xSize:0, ySize:0 }); fw.exportDocumentAs(doc,null,null); fw.closeDocument(doc,false);
赤丸を入れる
何かを目立たせるのに
fw.getDocumentDOM().addNewImage({left:0, top:0, right:100, bottom:100}, true); fw.getDocumentDOM().setFill(null); fw.getDocumentDOM().setBrushNColor({ alphaRemap:"none", angle:0, antiAliased:true, aspect:100, blackness:0, category:"bc_Pencil", concentration:100, dashOffSize1:2, dashOffSize2:2, dashOffSize3:2, dashOnSize1:8, dashOnSize2:1, dashOnSize3:1, diameter:3, feedback:"brush", flowRate:0, maxCount:15, minSize:1, name:"bn_1-Pixel Anti-Aliased", numDashes:0, shape:"circle", softenMode:"bell curve", softness:0, spacing:15, textureBlend:0, textureEdge:0, tipColoringMode:"random", tipCount:1, tipSpacing:0, tipSpacingMode:"random", type:"simple" }, "#ff0000"); fw.getDocumentDOM().addNewOval({left:50, top:50, right:80, bottom:80});