<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[PunBB Forums — Automatic Avatar Resizing]]></title>
		<link>https://punbb.informer.com/forums/topic/22625/automatic-avatar-resizing/</link>
		<atom:link href="https://punbb.informer.com/forums/feed/rss/topic/22625/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Automatic Avatar Resizing.]]></description>
		<lastBuildDate>Sun, 28 Nov 2010 17:50:24 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Automatic Avatar Resizing]]></title>
			<link>https://punbb.informer.com/forums/post/138717/#p138717</link>
			<description><![CDATA[<p>Thanks for the mod, it works quite well.</p><p>Cheers!</p>]]></description>
			<author><![CDATA[null@example.com (Gene53)]]></author>
			<pubDate>Sun, 28 Nov 2010 17:50:24 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/138717/#p138717</guid>
		</item>
		<item>
			<title><![CDATA[Re: Automatic Avatar Resizing]]></title>
			<link>https://punbb.informer.com/forums/post/132798/#p132798</link>
			<description><![CDATA[<p>If I&#039;m honest I&#039;m unsure how to the extension system works, if you can point me in the direction of some info on creating these I will be happy to work on the release</p>]]></description>
			<author><![CDATA[null@example.com (Source Code)]]></author>
			<pubDate>Sat, 12 Dec 2009 07:45:47 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/132798/#p132798</guid>
		</item>
		<item>
			<title><![CDATA[Re: Automatic Avatar Resizing]]></title>
			<link>https://punbb.informer.com/forums/post/132797/#p132797</link>
			<description><![CDATA[<p>Could you create an extension based on this mod, please?</p>]]></description>
			<author><![CDATA[null@example.com (Slavok)]]></author>
			<pubDate>Sat, 12 Dec 2009 07:18:15 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/132797/#p132797</guid>
		</item>
		<item>
			<title><![CDATA[Automatic Avatar Resizing]]></title>
			<link>https://punbb.informer.com/forums/post/132789/#p132789</link>
			<description><![CDATA[<p>I did not create this mod, I simply reworked some coding from a punbb 1.2 mod, all credit goes to the original author &quot;thame^&quot; who&#039;s mod for 1.2 can be found <a href="http://punbb.informer.com/forums/topic/16883/automatically-resize-uploaded-avatars/">here</a></p><div class="codebox"><pre><code>##
##        Mod title:  Automatically resize uploaded avatars
##
##      Mod version:  1.0
##   Works on PunBB:  1.3.*
##     Release date:  2009-12-11
##         Original Author:  thame^
##         Update Author:  Source Code
##
##      Description:  PunBB&#039;s default behaviour is to reject any uploaded avatar
##                    image whose dimensions exceed those set in the options.
##                    Using this mod, PunBB will attempt to automatically resize
##                    those images to the maximum allowed dimensions, maintaining
##                    their aspect ratio. If the file size of the _resized image_
##                    is larger than allowed by the options, the upload will still
##                    be rejected.
##
##   Affected files:  profile.
##
##       Affects DB:  No
##
##            Notes:  This mod requires the GD image library, including support
##                    for at least JPEG (GIF and PNG are also recommended). If
##                    your copy of PHP is compiled without GD support (or lacks
##                    support for the uploaded image type), the mod will silently
##                    revert to the default PunBB behaviour. Visit
##                    http://php.net/gd for more information about the GD image
##                    library.
##
##       DISCLAIMER:  Please note that &quot;mods&quot; are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##


#
#---------[ 1. OPEN ]---------------------------------------------------------
#

profile.php


#
#---------[ 2. FIND ]-----------------------------------------------
#

            // Now check the width/height
            list($width, $height, $type,) = getimagesize($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
            if (empty($width) || empty($height) || $width &gt; $forum_config[&#039;o_avatars_width&#039;] || $height &gt; $forum_config[&#039;o_avatars_height&#039;])
            {
                @unlink($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
                message($lang_profile[&#039;Too wide or high&#039;].&#039; &#039;.$forum_config[&#039;o_avatars_width&#039;].&#039;x&#039;.$forum_config[&#039;o_avatars_height&#039;].&#039; &#039;.$lang_profile[&#039;pixels&#039;].&#039;.&#039;);
            }
            else if ($type == 1 &amp;&amp; $uploaded_file[&#039;type&#039;] != &#039;image/gif&#039;)    // Prevent dodgy uploads
            {
                @unlink($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
                message($lang_profile[&#039;Bad type&#039;]);
            }            


#
#---------[ 3. REPLACE WITH ]--------------------------------------------------
#

            // Now check the width/height
            list($width, $height, $type,) = getimagesize($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
            if (empty($width) || empty($height) || $width &gt; $forum_config[&#039;o_avatars_width&#039;] || $height &gt; $forum_config[&#039;o_avatars_height&#039;])
            {

                // Attempt to resize if GD is installed with support for the uploaded image type, as well as JPG for the output
                $check_type = str_replace(array(1, 2, 3), array(&#039;IMG_GIF&#039;, &#039;IMG_JPG&#039;, &#039;IMG_PNG&#039;), $type);
                if (extension_loaded(&#039;gd&#039;) &amp;&amp; imagetypes() &amp; constant($check_type) &amp;&amp; imagetypes() &amp; IMG_JPG)
                {

                    // Load the image for processing
                    if ($type == 1) $src_img = @imagecreatefromgif($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
                    elseif ($type == 2) $src_img = @imagecreatefromjpeg($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
                    elseif ($type == 3) $src_img = @imagecreatefrompng($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);

                    if ($src_img)
                    {

                        // Figure out new image dimensions based on the maximum width
                        $new_w = $forum_config[&#039;o_avatars_width&#039;];
                        $ratio = $height * $new_w;
                        $new_h = $ratio / $width;

                        // Do the new dimensions, based on the maximum width, fit the maximum height? If not, recalculate
                        if ($new_h &gt; $forum_config[&#039;o_avatars_height&#039;])
                        {
                            $new_h = $forum_config[&#039;o_avatars_height&#039;];
                            $ratio = $width * $new_h;
                            $new_w = $ratio / $height;
                        }

                        // Resize the image
                        $new_img = imagecreatetruecolor($new_w, $new_h);
                        imagecopyresampled($new_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $width, $height);

                        // Delete the old image and write the newly resized one
                        @unlink($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
                        imagejpeg($new_img,$forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;,85);

                        // Set the extension to JPG, since that&#039;s what the resized image is now
                        $extensions[0] = &#039;.jpg&#039;;
                    }

                    // Something went wrong while attempting to load the image for processing
                    else
                    {
                        @unlink($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
                        message(&#039;An unexpected error occured while attempting to resize the image.&#039;);
                    }
                }

                // No GD installed or image type not supported; can&#039;t resize
                else
                {
                    @unlink($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
                    message($lang_profile[&#039;Too wide or high&#039;].&#039; &#039;.$forum_config[&#039;o_avatars_width&#039;].&#039;x&#039;.$forum_config[&#039;o_avatars_height&#039;].&#039; &#039;.$lang_profile[&#039;pixels&#039;].&#039;.&#039;);
                }
            }
            else if ($type == 1 &amp;&amp; $uploaded_file[&#039;type&#039;] != &#039;image/gif&#039;)    // Prevent dodgy uploads
            {
                @unlink($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;);
                message($lang_profile[&#039;Bad type&#039;]);
            }

            // Make sure the file isn&#039;t too big
            if (filesize($forum_config[&#039;o_avatars_dir&#039;].&#039;/&#039;.$id.&#039;.tmp&#039;) &gt; $forum_config[&#039;o_avatars_size&#039;])
                message($lang_profile[&#039;Too large&#039;].&#039; &#039;.$forum_config[&#039;o_avatars_size&#039;].&#039; &#039;.$lang_profile[&#039;bytes&#039;].&#039;.&#039;);


#
#---------[ 4. FIND &amp; DELETE ORIGINAL LINES ( AROUND 1175 ) ]-----------------------------------------------
#

            // Make sure the file isn&#039;t too big
            if ($uploaded_file[&#039;size&#039;] &gt; $forum_config[&#039;o_avatars_size&#039;])
                message($lang_profile[&#039;Too large&#039;].&#039; &#039;.$forum_config[&#039;o_avatars_size&#039;].&#039; &#039;.$lang_profile[&#039;bytes&#039;].&#039;.&#039;);


#
#---------[ 5. SAVE/UPLOAD ]-------------------------------------------------
#</code></pre></div><br /><p>Again I did not create this mod and full credit goes to the original author, I have simply updated it to work with punbb 1.3.</p>]]></description>
			<author><![CDATA[null@example.com (Source Code)]]></author>
			<pubDate>Fri, 11 Dec 2009 18:16:07 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/132789/#p132789</guid>
		</item>
	</channel>
</rss>
