<?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>WebHive Blog &#187; Programming</title>
	<atom:link href="http://webhive.com.ua/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://webhive.com.ua/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 02 Nov 2010 12:01:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SocialEngine correct image resizing</title>
		<link>http://webhive.com.ua/blog/socialengine-correct-image-resizing-part-1/</link>
		<comments>http://webhive.com.ua/blog/socialengine-correct-image-resizing-part-1/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 16:14:21 +0000</pubDate>
		<dc:creator>Eugene Sutula</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[SocialEngine]]></category>

		<guid isPermaLink="false">http://webhive.com.ua/blog/?p=16</guid>
		<description><![CDATA[This was the first thing I&#8217;ve found in SocialEngine that should be enhanced.
As you may have noticed SocialEngine in most of cases resizes images using html width and height options.
While this is the easiest technique it&#8217;s not the best one. If you want to keep the high quality of images uploaded by users you need [...]]]></description>
			<content:encoded><![CDATA[<p>This was the first thing I&#8217;ve found in SocialEngine that should be enhanced.<br />
As you may have noticed SocialEngine in most of cases resizes images using html width and height options.<br />
While this is the easiest technique it&#8217;s not the best one. If you want to keep the high quality of images uploaded by users you need to find another solution here.</p>
<p>I&#8217;ve created a mod that can help you to solve this problem. It uses caching, so it will increase the page loading speed of your website.<br />
Let me demonstrate how you can resize images using phpthumb library.</p>
<p>To install this mod you need to follow the next steps</p>
<p>1. Download the mod from <a href="http://webhive.com.ua/products/se_thumb.html">http://webhive.com.ua/products/se_thumb.html</a><br />
and copy all files from archive to your SocialEngine folder.<br />
2. Set permissions &#8216;777&#8242; to folders thumbs/cache and thumbs/tmp after upload.</p>
<p>3. Download phpThumb library from<br />
<a href="http://phpthumb.sourceforge.net/#download">http://phpthumb.sourceforge.net/#download</a><br />
Take the latest stable version you see there (1.7.8 at the moment of writing this doc)<br />
Unzip it and upload to folder include/phpThumb/ in your SocialEngine directory.</p>
<p>4. Now we will need to edit some files (I advise you to make backup copies of all files you will edit).</p>
<p>Let&#8217;s create a function that will output thumbnails of the image instead of original images<br />
<strong>include/class_user.php</strong><br />
Go to the end of file and add before last brace (&#8220;}&#8221;) next code:</p>
<div class="geshi no php">
<div class="head">function user_thumb($nophoto_image = &#8220;&#8221;, $w=90, $h=90) {</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$user_id</span> <span class="sy0">=</span> <span class="re1">$this</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>user_info<span class="br0">&#91;</span>user_id<span class="br0">&#93;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$subdir</span> <span class="sy0">=</span> <span class="re1">$user_id</span><span class="nu0">+999</span><span class="sy0">-</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re1">$user_id</span><span class="nu0">-1</span><span class="br0">&#41;</span><span class="sy0">%</span><span class="nu0">1000</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$userdir</span> <span class="sy0">=</span> <span class="st0">&quot;uploads_user/$subdir/$user_id/&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$user_photo</span> <span class="sy0">=</span> <span class="re1">$userdir</span><span class="sy0">.</span><span class="re1">$this</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>user_info<span class="br0">&#91;</span>user_photo<span class="br0">&#93;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">file_exists</span><span class="br0">&#40;</span><span class="re1">$user_photo</span><span class="br0">&#41;</span> <span class="sy0">|</span> <span class="re1">$this</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>user_info<span class="br0">&#91;</span>user_photo<span class="br0">&#93;</span> <span class="sy0">==</span> <span class="st0">&quot;&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="re1">$user_photo</span> <span class="sy0">=</span> <span class="re1">$nophoto_image</span><span class="sy0">;</span> <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$user_photo</span> <span class="sy0">=</span> <span class="st0">&#39;./show_thumb.php?src=&#39;</span><span class="sy0">.</span><span class="re1">$user_photo</span><span class="sy0">.</span><span class="st0">&quot;&amp;amp;w=&quot;</span><span class="sy0">.</span><span class="re1">$w</span><span class="sy0">.</span><span class="st0">&quot;&amp;amp;h=&quot;</span><span class="sy0">.</span><span class="re1">$h</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">return</span> <span class="re1">$user_photo</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="co1">// END user_thumb() METHOD</span></div>
</li>
</ol>
</div>
<p>Now we will need to increase the quality of newly uploaded images from 75%(default) to 100%</p>
<p><strong>include/class_upload.php</strong><br />
Search for next code (you will find 4 occurrences):</p>
<div class="geshi no php">
<div class="head">imagejpeg($file, $photo_dest);</div>
<ol>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>pre<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">and change all <span class="nu0">4</span> occurrences of this code to</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>pre lang<span class="sy0">=</span><span class="st0">&quot;php&quot;</span><span class="sy0">&gt;</span>imagejpeg<span class="br0">&#40;</span><span class="re1">$file</span><span class="sy0">,</span> <span class="re1">$photo_dest</span><span class="sy0">,</span> <span class="nu0">100</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>Now when our mod is installed we need is to replace the links from big images resized with html with links to our thumbnail generator</p>
<p><strong>templates/home.tpl</strong></p>
<p>Search for next code (line ~152):</p>
<div class="geshi no html4strict">
<div class="head"><img class="photo" src="{$signups[signups_loop]-&gt;user_photo(" border="0" alt="" width="{$misc-&gt;photo_size($signups[signups_loop]-&gt;user_photo(" /></div>
<ol>
<li class="li1">
<div class="de1"><span class="sc2"><span class="kw2">&lt;/pre&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">Change to</div>
</li>
<li class="li1">
<div class="de1"><span class="sc2"><span class="kw2">&lt;pre</span> <span class="kw3">lang</span><span class="sy0">=</span><span class="st0">&quot;html4strict&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;img</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;photo&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;{$signups[signups_loop]-&amp;gt;user_thumb(&quot;</span> <span class="kw3">border</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;{$misc-&amp;gt;photo_size($signups[signups_loop]-&amp;gt;user_photo(&quot;</span> <span class="sy0">/</span><span class="kw2">&gt;</span></span></div>
</li>
</ol>
</div>
<p>Search for code (line ~178):</p>
<div class="geshi no html4strict">
<div class="head"><img class="photo" src="{$friends[friends_loop].friend-&gt;user_photo(" border="0" alt="" width="{$misc-&gt;photo_size($friends[friends_loop].friend-&gt;user_photo(" /></div>
<ol>
<li class="li1">
<div class="de1"><span class="sc2"><span class="kw2">&lt;/pre&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">Change to</div>
</li>
<li class="li1">
<div class="de1"><span class="sc2"><span class="kw2">&lt;pre</span> <span class="kw3">lang</span><span class="sy0">=</span><span class="st0">&quot;html4strict&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;img</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;photo&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;{$friends[friends_loop].friend-&amp;gt;user_thumb(&quot;</span> <span class="kw3">border</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;{$misc-&amp;gt;photo_size($friends[friends_loop].friend-&amp;gt;user_photo(&quot;</span> <span class="sy0">/</span><span class="kw2">&gt;</span></span></div>
</li>
</ol>
</div>
<p>Search for code:</p>
<div class="geshi no html4strict">
<div class="head"><img class="photo" src="{$logins[login_loop]-&gt;user_photo(" border="0" alt="" width="{$misc-&gt;photo_size($logins[login_loop]-&gt;user_photo(" /></div>
<ol>
<li class="li1">
<div class="de1"><span class="sc2"><span class="kw2">&lt;/pre&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">Change to</div>
</li>
<li class="li1">
<div class="de1"><span class="sc2"><span class="kw2">&lt;pre</span> <span class="kw3">lang</span><span class="sy0">=</span><span class="st0">&quot;html4strict&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;img</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;photo&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;{$logins[login_loop]-&amp;gt;user_thumb(&quot;</span> <span class="kw3">border</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;{$misc-&amp;gt;photo_size($logins[login_loop]-&amp;gt;user_photo(&quot;</span> <span class="sy0">/</span><span class="kw2">&gt;</span></span></div>
</li>
</ol>
</div>
<p>Now when all images on your home page are beautifully resized, let&#8217;s proceed and make all images on profile page look great too</p>
<p><strong>templates/profile.tpl</strong></p>
<p>Search for code(line ~395)</p>
<div class="geshi no html4strict">
<div class="head"><a href="{$url-&gt;url_create(">user_info.user_username)}&#39;&gt;<img class="photo" src="{$comments[comment_loop].comment_author-&gt;user_photo(" border="0" alt="" width="{$misc-&gt;photo_size($comments[comment_loop].comment_author-&gt;user_photo(" /></a></div>
<ol>
<li class="li1">
<div class="de1"><span class="sc2"><span class="kw2">&lt;/pre&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">Change to</div>
</li>
<li class="li1">
<div class="de1"><span class="sc2"><span class="kw2">&lt;pre</span> <span class="kw3">lang</span><span class="sy0">=</span><span class="st0">&quot;html4strict&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;a</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;{$url-&amp;gt;url_create(&quot;</span><span class="kw2">&gt;</span></span>user_info.user_username)}&#39;<span class="sc1">&amp;gt;</span><span class="sc2"><span class="kw2">&lt;img</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;photo&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;{$comments[comment_loop].comment_author-&amp;gt;user_photo(&quot;</span> <span class="kw3">border</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;{$misc-&amp;gt;photo_size($comments[comment_loop].comment_author-&amp;gt;user_thumb(&quot;</span> <span class="sy0">/</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;/a&gt;</span></span></div>
</li>
</ol>
</div>
<p>I will try to cover the rest of the SocialEngine pages in future posts, but if you have understood what we have done you can try to do it yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://webhive.com.ua/blog/socialengine-correct-image-resizing-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

