function resize_img($oldFile, $newFile, $newWidth, $newHeight, $method, $stretch, $jpgQuality, $fillR, $fillG, $fillB) { $imageInfo = getimagesize($oldFile); switch ($imageInfo[2]) { case 1: $oldImage = imagecreatefromgif($oldFile); break; case 2: $oldImage = imagecreatefromjpeg($oldFile); break; case 3: $oldImage = imagecreatefrompng($oldFile); break; } if ($method == 'shrink') { if (!$stretch && $imageInfo[0] < $newWidth && $imageInfo[1] < $newHeight) { $newImage = imagecreatetruecolor($imageInfo[0], $imageInfo[1]); imagecopyresampled($newImage, $oldImage, 0, 0, 0, 0, $imageInfo[0], $imageInfo[1], $imageInfo[0], $imageInfo[1]); } else { if ($imageInfo[0] / $imageInfo[1] >= $newWidth / $newHeight) { $newImage = imagecreatetruecolor($newWidth, $newWidth * $imageInfo[1] / $imageInfo[0]); imagecopyresampled($newImage, $oldImage, 0, 0, 0, 0, $newWidth, $newWidth * $imageInfo[1] / $imageInfo[0], $imageInfo[0], $imageInfo[1]); } else { $newImage = imagecreatetruecolor($imageInfo[0] * $newHeight / $imageInfo[1], $newHeight); imagecopyresampled($newImage, $oldImage, 0, 0, 0, 0, $imageInfo[0] * $newHeight / $imageInfo[1], $newHeight, $imageInfo[0], $imageInfo[1]); } } imagejpeg($newImage, $newFile, $jpgQuality); } elseif ($method == 'crop') { $newImage = CroppedThumbnail($imageInfo[0], $imageInfo[1], $newWidth, $newHeight, $oldImage); imagejpeg($newImage, $newFile, $jpgQuality); } elseif ($method == 'fit') { $newImage = imagecreatetruecolor($newWidth, $newHeight); $color = imagecolorallocate($newImage, $fillR, $fillG, $fillB); imagefill($newImage, 0, 0, $color); if (!$stretch && ($imageInfo[0] < $newWidth && $imageInfo[1] < $newHeight)) { imagecopyresampled($newImage, $oldImage, floor(($newWidth - $imageInfo[0]) / 2), floor(($newHeight - $imageInfo[1]) / 2), 0, 0, $imageInfo[0], $imageInfo[1], $imageInfo[0], $imageInfo[1]); } else { if ($imageInfo[0] / $imageInfo[1] >= $newWidth / $newHeight) { imagecopyresampled($newImage, $oldImage, 0, floor(($newHeight - $newWidth * $imageInfo[1] / $imageInfo[0]) / 2), 0, 0, $newWidth, $newWidth * $imageInfo[1] / $imageInfo[0], $imageInfo[0], $imageInfo[1]); } else { imagecopyresampled($newImage, $oldImage, floor(($newWidth - $imageInfo[0] * $newHeight / $imageInfo[1]) / 2), 0, 0, 0, $imageInfo[0] * $newHeight / $imageInfo[1], $newHeight, $imageInfo[0], $imageInfo[1]); } } imagejpeg($newImage, $newFile, $jpgQuality); } }
//Determines where to set the X position of the text box so it is centered. $textY = ceil(($height - $textHeight) / 2 + $textHeight); //Determines where to set the Y position of the text box so it is centered. $bordersize = $width > $height ? $height * 0.1 : $width * 0.1; //Special RE stuff switch ($re_special) { case 'reland': $img = CroppedThumbnail('background.png', $width, $height); $img = addBorderpng($img, $bordersize, $bg_colorhex); break; case 'video': $img = CroppedThumbnail('video.png', $width, $height); $img = addBorderpng($img, $bordersize, $bg_colorhex); break; case 'bust': $img = CroppedThumbnail('silhouette.png', $width, $height); break; default: imageFilledRectangle($img, 0, 0, $width, $height, $bg_color); //Creates the rectangle with the specified background color. http://us2.php.net/manual/en/function.imagefilledrectangle.php break; } $fg_color = imageColorAllocate($img, $foreground->get_rgb('r'), $foreground->get_rgb('g'), $foreground->get_rgb('b')); if (function_exists('imagettftext')) { imagettftext($img, $fontsize, $text_angle, $textX, $textY, $fg_color, $font, $text); //Create and positions the text http://us2.php.net/manual/en/function.imagettftext.php } $offset = 60 * 60 * 24 * 14; //14 Days $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; header($ExpStr);