Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
Resize image to canvas
<pre class='prettyprint' language='php'>/** * Scale an image according to input canvas dimensions. * No cropping will occur, the scaled image is "centered" to canvas. */ function imageToCanvas ($_image, $_canvasWidth, $_canvasHeight) { if (is_string($_image)) { if (is_file($_image)) { $_image = imagecreatefromjpeg($_image); } else { return "Incorrect imagepath >> No file here " . $_image; } } $width = imagesx($_image); $height = imagesy($_image); $image_aspect_ratio = $width / $height; $canvas_aspect_ratio = $_canvasWidth / $_canvasHeight; // scale by height if ($image_aspect_ratio < $canvas_aspect_ratio) { $new_height = $_canvasHeight; $new_width = ($new_height/$height) * $width; } // scale by width else { $new_width = $_canvasWidth; $new_height = ($new_width/$width) * $height; } # offset values (ie. center the resized image to canvas) $xoffset = ($_canvasWidth - $new_width) / 2; $yoffset = ($_canvasHeight - $new_height) / 2; $image_resized = imagecreatetruecolor($_canvasWidth, $_canvasHeight); # fill colour $white = imagecolorallocate($image_resized, 255, 255, 255); imagefill($image_resized, 0, 0, $white); imagecopyresampled($image_resized, $_image, $xoffset, $yoffset, 0, 0, $new_width, $new_height, $width, $height); imagedestroy($_image); return $image_resized; }</pre> <a href="http://www.refactormycode.com/codes/433-resize-image-to-canvas" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>