All pastes #958674 Raw Edit

Transparent Thumbnails

public php v1 · immutable
#958674 ·published 2008-03-26 21:22 UTC
rendered paste body
<?php	// Thumbnail	$id = intval($_GET['img']);	require_once('include.php');	if (file_exists("thumbs/$id.png"))	{		header("Location: thumbs/$id.png");die();	}	$q = $site->db->singleQuery("SELECT * FROM `z_dp_logos` WHERE `id`='$id' LIMIT 1");	$name = $q['name'];	$image = "logos/".$name;	$t = getimagesize($image);	$ox = $t[0];	$oy = $t[1];	if($t[2] == IMAGETYPE_GIF) { $img1 = imagecreatefromgif($image); }	if($t[2] == IMAGETYPE_JPEG) { $img1 = imagecreatefromjpeg($image); }	if($t[2] == IMAGETYPE_PNG) { $img1 = imagecreatefrompng($image); }	imageAlphaBlending($img1,false);	imageSaveAlpha($img1,true);	if ($ox < 100 && $oy < 100)	{		$nx = $ox;		$ny = $oy;	}	elseif ($ox > $oy)	{		$nx = 100;		$ny = (100 * $oy) / $ox;	}	else	{		$ny = 100;		$nx = (100 * $ox) / $oy;	}	$img2 = imagecreatetruecolor($nx,$ny);	imageAlphaBlending($img2,false);	imagecopyresampled($img2,$img1,0,0,0,0,$nx,$ny,$ox,$oy);	imagedestroy($img1);	imageSaveAlpha($img2,true);//	header("Content-Type: image/png");	imagepng($img2,"thumbs/$id.png");	header("Location: thumbs/$id.png");?>