<?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>PageTalks &#187; resize</title>
	<atom:link href="http://pagetalks.com/tag/resize/feed" rel="self" type="application/rss+xml" />
	<link>http://pagetalks.com</link>
	<description>Pure Web Development &#38; Design Ideas</description>
	<lastBuildDate>Thu, 19 Jan 2012 12:06:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Disable Image Resizing in Thickbox</title>
		<link>http://pagetalks.com/2008/08/29/disable-image-resizing-in-thickbox.html</link>
		<comments>http://pagetalks.com/2008/08/29/disable-image-resizing-in-thickbox.html#comments</comments>
		<pubDate>Fri, 29 Aug 2008 09:00:22 +0000</pubDate>
		<dc:creator>Robin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://pagetalks.com/?p=56</guid>
		<description><![CDATA[Thickbox对图片的处理相当相当智能，其中就包括图片的缩放，也就是当图片实际大小超过窗口大小的时候，脚本会自动把图片缩放到适当大小显 示，让图片不至于溢出。但这个带来一个比较麻... ]]></description>
			<content:encoded><![CDATA[<div lang="zh">Thickbox对图片的处理相当相当智能，其中就包括图片的缩放，也就是当图片实际大小超过窗口大小的时候，脚本会自动把图片缩放到适当大小显 示，让图片不至于溢出。但这个带来一个比较麻烦的事情，由于是通过简单改变IMG标签的width和height属性达到的缩放会使图片产生许多粗糙边缘 以及细节的丢失。于是大家开始寻找废掉这个“智能”的方法……汗~</p>
<h3>源头在哪里？</h3>
<p>打开thickbox.js，大家不难发现，图片Resize的代码就是如下这段：</p>
<pre>var pagesize = tb_getPageSize();
var x = pagesize[0] - 150;
var y = pagesize[1] - 150;
var imageWidth = imgPreloader.width;
var imageHeight = imgPreloader.height;
if (imageWidth &gt; x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
if (imageHeight &gt; y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
}
} else if (imageHeight &gt; y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
if (imageWidth &gt; x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
}
}</pre>
<p>很显然在这里就可以直接废掉它的机制，将以上代码替换为：</p>
<pre>var imageWidth = imgPreloader.width;
var imageHeight = imgPreloader.height;</pre>
<p>这样图片始终将以原始大小输出，如果浏览器没有特殊的自动缩放功能，那么图片将最终处于100%状态。
</p></div>
<div lang="en">Thickbox is quite intelligent on handling the images, e.g, it aotomatically resizes the images if it&#8217;s too large for the thickbox containers. Unfortunately , this is often not the intent of our own&#8230;</p>
<h3>Where is the root?</h3>
<p>Simply open thickbox.js, it&#8217;s easy to find the resizing is driven by the code below: </p>
<pre>var pagesize = tb_getPageSize();
var x = pagesize[0] - 150;
var y = pagesize[1] - 150;
var imageWidth = imgPreloader.width;
var imageHeight = imgPreloader.height;
if (imageWidth &gt; x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
if (imageHeight &gt; y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
}
} else if (imageHeight &gt; y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
if (imageWidth &gt; x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
}
}</pre>
<p>If you just want to disble it for good, don&#8217;t hesitate to replace the code above with these: </p>
<pre>var imageWidth = imgPreloader.width;
var imageHeight = imgPreloader.height;</pre>
<p>Finnaly thickbox displays the image in original size. Cheers!
</p></div>
<p><span id="more-56"></span></p>
<div lang="zh">
<h3>问题解决了？</h3>
<p>别高兴的太早！毕竟人家写Resize的代码是有用处的——因为Thickbox的窗口即使溢出，其主窗口也不会产生滚动条。也就是说，就算图片超过了屏幕，用户也不能通过滚动条浏览到图片全貌。这不是得不偿失么？！慢慢来……慢慢来……<br />
解决思路可以是如下的：<br />
1、如果图片能够在当前窗口100%显示且不会造成益处，系统就没有必要Resize<br />
2、图片太大无法在当前窗口以100%大小显示，需要Resize的时候，我们提供额外的全尺寸图片链接。<br />
这是目前最直接也是最有效的方法了……</p>
<p>我们首先还是需要找到之前的那段关于Resize的代码，将其替换为如下：</p>
<pre>var pagesize = tb_getPageSize();
var resized = false;
var x = pagesize[0] - 150;
var y = pagesize[1] - 150;
var imageWidth = imgPreloader.width;
var imageHeight = imgPreloader.height;
if (imageWidth &gt; x) {
resized = true;
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
if (imageHeight &gt; y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
}
} else if (imageHeight &gt; y) {
resized = true;
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
if (imageWidth &gt; x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
}
}</pre>
<p>其实无非是加入了一个名称为resized的布尔值变量，作为是否Resized判断。</p>
<p>紧接着我们要加入源文件链接，找到如下代码：</p>
<pre>$("#TB_window").append("&lt;a href='' id='TB_ImageOff' title='Close'&gt;&lt;img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/&gt;&lt;/a&gt;" + "&lt;div id='TB_caption'&gt;"+caption+"&lt;div id='TB_secondLine'&gt;" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "&lt;/div&gt;&lt;/div&gt;&lt;div id='TB_closeWindow'&gt;&lt;a href='#' id='TB_closeWindowButton' title='Close'&gt;close&lt;/a&gt; or Esc Key&lt;/div&gt;");</pre>
<p>稍微分析一下，你会发现这是thickbox窗口生成显示图片的代码。替换成如下：</p>
<pre>if(!resized){
$("#TB_window").append("&lt;a href='' id='TB_ImageOff' title='Close'&gt;&lt;img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/&gt;&lt;/a&gt;" + "&lt;div id='TB_caption'&gt;"+caption+"&lt;div id='TB_secondLine'&gt;" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "&lt;/div&gt;&lt;/div&gt;&lt;div id='TB_closeWindow'&gt;&lt;a href='#' id='TB_closeWindowButton' title='Close'&gt;close&lt;/a&gt; or Esc Key&lt;/div&gt;");
} else {
$("#TB_window").append("&lt;a href='' id='TB_ImageOff' title='Close'&gt;&lt;img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/&gt;&lt;/a&gt;" + "&lt;div id='TB_caption'&gt;"+caption+" &lt;span style='color: rgb(255, 0, 0); font-weight: bold;'&gt;&lt;a href='"+url+"' target='_blank'&gt;CLICK FOR ORIGINAL SIZE&lt;/a&gt;&lt;/span&gt;"+"&lt;div id='TB_secondLine'&gt;" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "&lt;/div&gt;&lt;/div&gt;&lt;div id='TB_closeWindow'&gt;&lt;a href='#' id='TB_closeWindowButton' title='Close'&gt;close&lt;/a&gt; or Esc Key&lt;/div&gt;");
}</pre>
<p>也就是如果之前resized变量为true，系统就会生成带有源文件链接的Thickbox窗口。至于链接样式，大家可以自己发挥……</p>
<p>事情就是这样，大家过上了幸福的生活……Orz~Thickbox的作者从此认识到自己Resize机制是多么不智能……
</p></div>
<div lang="en">
<h3>Problem Solved?</h3>
<p>It seems it works all right. What if the image is large enough to overflow the thickbox? You know that&#8217;s why the sophisticated developer type these code in their project to enable resizing. Let&#8217;s think better:<br />
1.If the image is fine with the thickbox, thus it won&#8217;t overflow. Well, resizing is not needed.<br />
2.If the image is large, let the script resize the image. Besides, we insert a link to the original file.<br />
Sounds like a plan?<br />
Let&#8217;s find the resizing code again, and replace it with the code below:</p>
<pre>var pagesize = tb_getPageSize();
var resized = false;
var x = pagesize[0] - 150;
var y = pagesize[1] - 150;
var imageWidth = imgPreloader.width;
var imageHeight = imgPreloader.height;
if (imageWidth &gt; x) {
resized = true;
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
if (imageHeight &gt; y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
}
} else if (imageHeight &gt; y) {
resized = true;
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
if (imageWidth &gt; x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
}
}</pre>
<p>In fact, I only create a boolean varible &#8220;resized&#8221; to flag if resized.<br />
Then we come back the thickbox.js, locate the code below:</p>
<pre>$("#TB_window").append("&lt;a href='' id='TB_ImageOff' title='Close'&gt;&lt;img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/&gt;&lt;/a&gt;" + "&lt;div id='TB_caption'&gt;"+caption+"&lt;div id='TB_secondLine'&gt;" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "&lt;/div&gt;&lt;/div&gt;&lt;div id='TB_closeWindow'&gt;&lt;a href='#' id='TB_closeWindowButton' title='Close'&gt;close&lt;/a&gt; or Esc Key&lt;/div&gt;");</pre>
<p>The code will control and create the elements in thickbox, you can modify as you wish. Here is mine: </p>
<pre>if(!resized){
$("#TB_window").append("&lt;a href='' id='TB_ImageOff' title='Close'&gt;&lt;img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/&gt;&lt;/a&gt;" + "&lt;div id='TB_caption'&gt;"+caption+"&lt;div id='TB_secondLine'&gt;" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "&lt;/div&gt;&lt;/div&gt;&lt;div id='TB_closeWindow'&gt;&lt;a href='#' id='TB_closeWindowButton' title='Close'&gt;close&lt;/a&gt; or Esc Key&lt;/div&gt;");
} else {
$("#TB_window").append("&lt;a href='' id='TB_ImageOff' title='Close'&gt;&lt;img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/&gt;&lt;/a&gt;" + "&lt;div id='TB_caption'&gt;"+caption+" &lt;span style='color: rgb(255, 0, 0); font-weight: bold;'&gt;&lt;a href='"+url+"' target='_blank'&gt;CLICK FOR ORIGINAL SIZE&lt;/a&gt;&lt;/span&gt;"+"&lt;div id='TB_secondLine'&gt;" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "&lt;/div&gt;&lt;/div&gt;&lt;div id='TB_closeWindow'&gt;&lt;a href='#' id='TB_closeWindowButton' title='Close'&gt;close&lt;/a&gt; or Esc Key&lt;/div&gt;");
}</pre>
<p>Obviously clear that if &#8220;resized&#8221; is true, it will insert a link where you assign in the previous code. Otherwise, peace&#8230;&#8230;</p>
<p>Well, the story ends&#8230;&#8230;You can try your plan. This is only a demostration how we can better or custom the thickbox.
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://pagetalks.com/2008/08/29/disable-image-resizing-in-thickbox.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
