source image datas // get -> target size datas // in -> input image // out -> output image datas $src = isset($_GET['imgSrc']) ? $_GET['imgSrc'] : false; $getWidth = isset($_GET['w']) ? $_GET['w'] : false; $getHeight = isset($_GET['h']) ? $_GET['h'] : false; $outType = isset($_GET['imgType']) ? $_GET['imgType'] : 'auto'; //jpg, png or auto $resizeType = isset($_GET['resizeType']) ? $_GET['resizeType'] : 'default'; //default, keep, crop or force $bgColor = isset($_GET['bgColor']) ? explode(',',$_GET['bgColor']) : array(255,255,255); $txt = isset($_GET['txt']) ? stripslashes($_GET['txt']) : false; $txtColor = isset($_GET['txtColor']) ? explode(',',$_GET['txtColor']) : array(255,255,255); $txtSize = isset($_GET['txtSize']) ? $_GET['txtSize'] : 'default'; //default, big or small $txtBgColor = isset($_GET['txtBgColor']) ? explode(',',$_GET['txtBgColor']): array(0,0,0); $txtBgAlpha = isset($_GET['txtBgAlpha']) ? $_GET['txtBgAlpha'] : 80; $inX = $inY = 0; // in from src if($src){ list($srcWidth,$srcHeight,$srcType)=getimagesize($src); switch($srcType){ case 1: $in=imagecreatefromgif($src); break; case 2: $in=imagecreatefromjpeg($src);break; case 3: $in=imagecreatefrompng($src); break; } } else $in=imagecreate($srcWidth=1,$srcHeight=1); // sizes computing if($getWidth&&$getHeight){ if($resizeType=='default'){ $outHeight=$srcHeight>$getHeight?$getHeight:$srcHeight; $outWidth=$outHeight*$srcWidth/$srcHeight; if($outWidth>$getWidth){ $outWidth=$srcWidth>$getWidth?$getWidth:$srcWidth; $outHeight=$outWidth*$srcHeight/$srcWidth; } $out=imagecreatetruecolor($finalWidth=$outWidth,$finalHeight=$outHeight); } else { if($resizeType=='crop'){ $outHeight=$srcHeight<$getHeight?$srcHeight:($srcHeight>$getHeight?$getHeight:$srcHeight); $outWidth=$outHeight*$srcWidth/$srcHeight; if($outWidth<$getWidth){ $outWidth=$srcWidth<$getWidth?$srcWidth:($srcWidth>$getWidth?$getWidth:$srcWidth); $outHeight=$outWidth*$srcHeight/$srcWidth; } } elseif($resizeType=='keep') { $outWidth=$srcWidth<$getWidth?$srcWidth:$getWidth; $outHeight=$srcHeight<$getHeight?$srcHeight:$getWidth*$srcHeight/$srcWidth; if($outHeight>$getHeight){ $outHeight=$getHeight; $outWidth=$getHeight*$srcWidth/$srcHeight; } } elseif($resizeType=='force') { $outWidth=$srcWidth<$getWidth?$srcWidth:$getWidth; $outHeight=$srcHeight<$getHeight?$srcHeight:$getHeight; } $inX=($getWidth-$outWidth)/2; $inY=($getHeight-$outHeight)/2; $out=imagecreatetruecolor($finalWidth=$getWidth,$finalHeight=$getHeight); } } // bg color $bg=imagecolorallocate($out,$bgColor[0],$bgColor[1],$bgColor[2]); imagefilledrectangle($out,0,0,$getWidth,$getHeight,$bg); // resampling if($src) imagecopyresampled($out,$in,$inX,$inY,0,0,$outWidth,$outHeight,$srcWidth,$srcHeight); imagedestroy($in); // txt print if($txt!==false){ //data preparation $txt=explode(' ',$txt); $txtSizesList=array('small'=>0,'default'=>2,'big'=>4); $txtSize=$txtSizesList[$txtSize]; $clr=imagecolorallocate($out,$txtColor[0],$txtColor[1],$txtColor[2]); $bg=imagecolorallocatealpha($out,$txtBgColor[0],$txtBgColor[1],$txtBgColor[2],$txtBgAlpha); $chars=''; $line=0; //foreach word foreach($txt as $word){ $test=$chars.' '.$word; //line lenght is bigger than width if(strlen($test)*($txtSize+4.5)>$finalWidth){ //print line without last word imagefilledrectangle($out,0,17*$line,$finalWidth,12+2*$txtSize+17*$line,$bg); imagestring($out,$txtSize,-2,2+15*$line,$chars,$clr); //increment line and reset line content $line++; $chars=' '.$word; } //add word to line else $chars.=' '.$word; } //print last words if($chars){ imagefilledrectangle($out,0,17*$line,$finalWidth,12+2*$txtSize+17*$line,$bg); imagestring($out,$txtSize,-2,2+15*$line,$chars,$clr); } } // out if($outType=='jpg'||($outType=='auto'&&$outHeight*$outWidth>5000)){ header('Content-Type: image/jpeg'); imagejpeg($out); } else{ header('Content-Type: image/png'); imagepng($out); } ?>