September 11, 2011

How to get image ratio for resize?

PHP: Hypertext Preprocessor

How to get image ratio for resize? It is an obvious question specially when you have to manipulate an image from small size to large or from large to small. As one of my friend don’t like to invent again a wheel but here we have to understand the manufacturing of a wheel for promising […]

August 10, 2011

How to add a postfix to a filename or image name?

function postfixToImg($postfix,$img_src) { $img = explode(‘.’,$img_src); $img[(count($img)-2)] = $img[(count($img)-2)].$postfix; $return = implode(‘.’,$img); return $return; }

get image proportions from smaller to larger or vice versa in php image maipulation

function positionFromSmallToLarge($positions=array(‘x’=>0,’y’=>0),$dms=array(‘w’=>0,’h’=>0),$dml=array(‘w’=>0,’h’=>0)) { #POSITIONS FOR LARGE IMAGE $largeX = 0;//UNKNOWN $largeY = 0;//UNKNOWN #DIMENSIONS LARGE ARE $largeWidth = $dml[‘w’]; $largeHeight = $dml[‘h’]; #DIMENSIONS SMALL ARE $smallWidth = $dms[‘w’]; $smallHeight = $dms[‘h’]; #POSITIONS OF AN OBJECT SPOTTED ON SMALL IMAGE ARE $smallX = $positions[‘x’]; $smallY = $positions[‘y’]; $percentFromLeft = ($smallX/$smallWidth); #CONSIDER IT IN PERCENT WITHOUT X […]

Resize image with PHP image libraries gd2 and imagick

function smart_resize_image($file, $width = 0, $height = 0, $proportional = false, $output = ‘file’, $delete_original = true, $use_linux_commands = false, $imagick=FALSE ) { if ( $height

getImgSrc a handy function in PHP image manipulation for php developers

function getImgSrc($fileName) { $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; } return $src; }

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

Merge two images with php image libraries gd2 and imagick

function mergeFrontBack($img_front, $img_back, $final_output, $x, $y, $imagick=FALSE) { if($imagick) { $overlay = new Imagick($img_front); $bg = new Imagick($img_back); $temp_image = new Imagick(); $d = $overlay->getImageGeometry(); $w = $d[‘width’]; $h = $d[‘height’]; $bg_temp = $this->prefixToImg(‘_temp’,$bg); $bg_copy = $this->prefixToImg(‘_copy’,$bg); $temp_image->newImage($w, $h, new ImagickPixel(‘white’)); $temp_image->setImageFormat(‘png’); $temp_image->writeImage($bg_temp); // Set the colorspace to the same value $temp_image->setImageColorspace($bg->getImageColorspace()); //Second image is […]

August 6, 2011

PHP Image Manipulation and Related Issues

PHP Image Manipulation and Related Issues Image manipulation in php is always remain as favorite as upload image functionality being better. Multiple uploader like fancy uploader using mootools lighten the image manipulation aspect once again. HTML 5 is coming up with the feature of progress bar and multiple uploads. This will certainly open another door […]