August 10, 2011

Skew and image with PHP image libaray gd2

function skewed($fileName, $dest, $skew_val)
{

$mime_type = getimagesize($fileName);

//print_r($mime_type);

switch($mime_type[‘mime’])
{
case ‘image/png’:
$src = imagecreatefrompng($fileName);

break;
case ‘image/gif’:
$src = imagecreatefromgif($fileName);

break;
case ‘image/jpeg’:
$src = imagecreatefromjpeg($fileName);

break;
case ‘image/wbmp’:
$src = imagecreatefromwbmp($fileName);

break;

}

$width = imagesx($src);
$height = imagesy($src);
$imgdest = imagecreatetruecolor($width, $height+($height*$skew_val));
$trans = imagecolorallocate($imgdest,0,0,0);
$temp=0;

for($x=0 ; $x<$width ; $x++) { for($y=0 ; $y<$height ; $y++) { imagecopy($imgdest, $src, $x, $y+$temp, $x, $y, 1, 1); imagecolortransparent($imgdest,$trans); } $temp+=$skew_val; } imagepng($imgdest, $dest); imagedestroy($src); imagedestroy($imgdest); }

Last updated: March 19, 2014