<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>HYPERDASH BLOG++ &#187; Design</title>
	<atom:link href="http://blog.hyperdash.com/category/design/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.hyperdash.com</link>
	<description>Digital, Design and Dev by HYPERDASH, MIDWARE from Tokyo Japan</description>
	<lastBuildDate>Mon, 01 Jun 2009 20:50:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PhotoshopでレイヤーサイズをカンバスサイズにフィットするJSX</title>
		<link>http://blog.hyperdash.com/121</link>
		<comments>http://blog.hyperdash.com/121#comments</comments>
		<pubDate>Wed, 18 Feb 2009 12:07:26 +0000</pubDate>
		<dc:creator>HYPERDASH</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSX]]></category>
		<category><![CDATA[Photoshop]]></category>

		<guid isPermaLink="false">http://blog.hyperdash.com/?p=121</guid>
		<description><![CDATA[PhotoshopのレイヤーをカンバスにフィットさせるJSXを書いてみました。
選択中レイヤー（複数選択可）のタテヨコ短い方を基準にフィットします。（タテヨコ長い方がカンバスからハミ出ますが、中央揃えされます）
サムネイ [...]]]></description>
			<content:encoded><![CDATA[<p>PhotoshopのレイヤーをカンバスにフィットさせるJSXを書いてみました。<br />
選択中レイヤー（複数選択可）のタテヨコ短い方を基準にフィットします。（タテヨコ長い方がカンバスからハミ出ますが、中央揃えされます）<br />
サムネイル大量に作るのにちょう便利。<br />
トリミングとかも早くなるよ！（別ドキュメントで必要な部分を切り出して、書き出したいサイズのドキュメントにコピペ→JSX発動）</p>
<p>下記コードを「レイヤーをカンバスにフィット.jsx」など適当な名前で保存してください。</p>
<div class="igBar"><span id="ljavascript-2"><a href="#" onclick="javascript:showPlainTxt('javascript-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite">
<div id="javascript-2">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> canvasWidth = activeDocument.<span style="color: #006600;">width</span>;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> canvasHeight = activeDocument.<span style="color: #006600;">height</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> layer = activeDocument.<span style="color: #006600;">activeLayer</span>;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> layerX = layer.<span style="color: #006600;">bounds</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">0</span><span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> layerY = layer.<span style="color: #006600;">bounds</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> layerWidth = layer.<span style="color: #006600;">bounds</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">2</span><span style="color: #66cc66;">&#93;</span> - layerX;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> layerHeight = layer.<span style="color: #006600;">bounds</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">3</span><span style="color: #66cc66;">&#93;</span> - layerY;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> rate;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>layerHeight * <span style="color: #66cc66;">&#40;</span>canvasWidth / layerWidth<span style="color: #66cc66;">&#41;</span>&gt;= canvasHeight<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// 拡大縮小倍率を白が出ないようにするため小数点以下第4位で切り上げ（この辺は調整してください）</span></div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; rate = Math.<span style="color: #006600;">ceil</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>canvasWidth <span style="color: #0066FF;">/ layerWidth<span style="color: #66cc66;">&#41;</span> * <span style="color: #CC0000;color:#800000;">10000</span><span style="color: #66cc66;">&#41;</span> /</span> <span style="color: #CC0000;color:#800000;">100</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// 拡大縮小倍率を白が出ないようにするため小数点以下第4位で切り上げ（この辺は調整してください）</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; rate = Math.<span style="color: #006600;">ceil</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>canvasHeight <span style="color: #0066FF;">/ layerHeight<span style="color: #66cc66;">&#41;</span> * <span style="color: #CC0000;color:#800000;">10000</span><span style="color: #66cc66;">&#41;</span> /</span> <span style="color: #CC0000;color:#800000;">100</span>;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// レイヤーをリサイズ</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">layer.<span style="color: #006600;">resize</span><span style="color: #66cc66;">&#40;</span>rate, rate<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">layerX = layer.<span style="color: #006600;">bounds</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">0</span><span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">layerY = layer.<span style="color: #006600;">bounds</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">layerWidth = layer.<span style="color: #006600;">bounds</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">2</span><span style="color: #66cc66;">&#93;</span> - layerX;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">layerHeight = layer.<span style="color: #006600;">bounds</span><span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">3</span><span style="color: #66cc66;">&#93;</span> - layerY;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// 中央寄せ</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#444466;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">layer.<span style="color: #006600;">translate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>canvasWidth - layerWidth<span style="color: #66cc66;">&#41;</span> <span style="color: #0066FF;">/ <span style="color: #CC0000;color:#800000;">2</span><span style="color: #66cc66;">&#41;</span> - layerX, <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>canvasHeight - layerHeight<span style="color: #66cc66;">&#41;</span> /</span> <span style="color: #CC0000;color:#800000;">2</span><span style="color: #66cc66;">&#41;</span> - layerY<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hyperdash.com/121/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
