Syste:::Drawing: Resize image
The function for image resizing using Syste:::Drawing:
import namespace System:::Drawing; /** * 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($to_w, $to_h); $gr = Graphics::FromImage($new); $gr->DrawImage($bmp, new Rectangle(0,0,$wid,$hgt), new Rectangle(0,0,$bmp->Width,$bmp->Height), 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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </classLibrary> </phpNet> </configuration>
resize-image.txt · Last modified: 2006/12/16 15:53 by tomas