All pastes #170744 Raw Edit

Stuff

public text v1 · immutable
·published 2006-09-14 19:41 UTC
rendered paste body
<?php
session_start();
include('common.php');

function createThumbNail($location, $mWidth, $mHeigth) {
	// Get image info from variable
	$url = $location;
	$img = getimagesize($url) or die();
	// Checks if URL is image
	if ( $img[2] == 1 )
	{
		$pic = imagecreatefromgif( $url ) or die();
	}
		else if ( $img[2] == 2 )
	{
		$pic = imagecreatefromjpeg( $url ) or die();
	}
	else if ( $img[2] ==3 )
	{
		$pic = imagecreatefrompng( $url ) or die();
	}
	else
	{
		exit();
	}
	// If an image is found and we can determine that it is an image 
	if ( $pic )
	{
		// Get width and height from the image
		$width = imagesx( $pic );
		$height = imagesy( $pic );
 
		// Width that thumbnail should be
		$twidth = $mWidth;
		// Valid width?
		if ( !is_numeric( $twidth ) || $twidth <= 0 || !intval( $twidth ) || $twidth > $width )
		{
			exit(); 
		}
		// Calculate the new height 
		//$theight = $twidth * $height / $width;
		$theight = $mHeigth;
		// Create new image
		$thumb = @imagecreatetruecolor ( $twidth, $theight ) or die ("Can't create Image!");
 
		// Resize the image into a thumb
		imagecopyresized($thumb, $pic, 0, 0, 0, 0, $twidth, $theight, $width, $height);
		// Change page type to a jpeg
		header ("Content-type: image/jpeg"); 
 
		// Create jpeg image from thumbnail
		imagejpeg($thumb,"",75); 
	}
	else
	{
		exit();
	}
}
$_GET['pic'] ?>