Code Samples/Resize image
From PhalangerWiki
[edit]
System.Drawing: Resize image
The function for image resizing using System.Drawing:
use System\Drawing;
use System\Drawing\Bitmap;
use System\Drawing\Graphics;
use System\Drawing\Rectangle;
/**
* Resize image using Bitmap and Graphics classes
* from the System:::Drawing namespace
*
* @param string $from File name of the source image
* @param string $to Target file name
* @param string $wid Target width
* @param string $hgt Target height
*
* @author Tomas Petricek <tomas@tomasp.net>
*/
function resize_imageSysDraw($from,$to,$wid,$hgt)
{
$bmp = Bitmap::FromFile($from);
$new = new Bitmap($wid, $hgt);
$gr = Graphics::FromImage($new);
$gr->DrawImage($bmp,
new Rectangle(0,0,$wid,$hgt),
new Rectangle(0,0,$bmp->Width,$bmp->Height),
Drawing\GraphicsUnit::Pixel);
$gr->Dispose();
$new->Save($to);
$new->Dispose();
}
You'll also need to add following section to your web config to allow PHP/CLR extensions and add reference to System.Drawing.dll assembly:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<phpNet>
<compiler>
<!-- Enable PHP/CLR -->
<set name="LanguageFeatures">
<add value="PhpClr" />
</set>
</compiler>
<!-- Add required libraries -->
<classLibrary>
<add assembly="mscorlib" />
<add assembly="System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="System.Drawing, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</classLibrary>
</phpNet>
</configuration>
