Jump to content

greyscale thumbnails


Woodburn2006

Recommended Posts

is there anyway of changing this function so that it creates greyscale thumbnails rather than coloured images?

 

<?
$db_path = "/customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/cp/db.inc";

function connect_to_sql($host,$usr,$pwd,$db)
{
	$connection = mysql_connect($host,$usr,$pwd);
    	mysql_select_db($db);
	if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

	return $connection;
}

################################################################################

function createthumb($name,$filename,$new_w,$new_h)
{
	$system=explode('.',$name); // split filename either side of the '.'
	if (preg_match('/jpg|jpeg|JPG/',$system[1])){ // if extension is jpg or jpeg
		$src_img=imagecreatefromjpeg($name); // create a copy of the image in jpg
	}
	if (preg_match('/png/',$system[1])){ // if extension is png
		$src_img=imagecreatefrompng($name); // create a copy of the image in png
	}
	$old_x=imageSX($src_img); // gets width of original image
	$old_y=imageSY($src_img); // gets height of original image
	if ($old_x > $old_y) { // if img is wider than high
		$thumb_w=$new_w; // sets width variable of new img
		$thumb_h=$old_y*($new_h/$old_x); // sets height variable by doing: height = original width * (100 / original height)
	}
	if ($old_x < $old_y) { // other way around from setting wider than high
		$thumb_w=$old_x*($new_w/$old_y);
		$thumb_h=$new_h;
	}
	if ($old_x == $old_y) { // if img is square sets variabls straight forwardly
		$thumb_w=$new_w;
		$thumb_h=$new_h;
	}
	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // creates image
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // copies into new image
	if (preg_match("/png/",$system[1])) // if old file extension is png
	{
		imagepng($dst_img,$filename); // extension of new image is png
	} else {
		imagejpeg($dst_img,$filename); // else extension of new image is jpeg or jpg
	}
	imagedestroy($dst_img); //destroys variable
	imagedestroy($src_img); 
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.