~ overflow ~

Archive for April 7th, 2010

Fedora 10 Valid Repos

by z3n on Apr.07, 2010, under Linux Happyness, Tips & Hints

Problem:
My fedora 10 repos stopped working.

Solution:

My host had the dedicated configurated with a single static mirror. I figured out that by removing the baseurl from repos and enabling the mirrorlist it would work just fine.

Download:

Fedora 10 Mirror Repos

Leave a Comment :, , , more...

PNG Watermarking images with PHP

by z3n on Apr.07, 2010, under Coding, Tips & Hints

Problem:

How to watermark images with png’s alphablending enabled?

Solution:

function image_overlap($background, $foreground, $overlapX=-1, $overlapY=-1) {
	$insertWidth = imagesx($foreground);
	$insertHeight = imagesy($foreground);

	$imageWidth = imagesx($background);
	$imageHeight = imagesy($background);

	$overlapX = ($overlapX == -1) ? $imageWidth-$insertWidth-5 : $overlapX;
	$overlapY = ($overlapY == -1) ? $imageHeight-$insertHeight-5 : $overlapY;

	imagecolortransparent($foreground,imagecolorat($foreground,0,0));
	imagecopymerge($background,$foreground,$overlapX,$overlapY,0,0,$insertWidth,$insertHeight,100);

	return $background;
}
function watermark($src,$watermark,$src_format,$quality=75) {
	if (file_exists($src)) {
		_o("Watermarking: ".$src."...",1);
		switch ($src_format) {
			case "jpg":
				$src_img=imagecreatefromjpeg($src);
				break;
			case "gif":
				$src_img=imagecreatefromgif($src);
				break;
			case "bmp":
				$src_img=imagecreatefrombmp($src);
				break;
			case "png":
				$src_img=imagecreatefrompng($src);
				break;
			default:
				die("Unknown format");
		}

		// prepare source
		$src_size=getimagesize($src);
		$img=imagecreatetruecolor($src_size[0],$src_size[1]);
		imagecopyresampled($img,$src_img,0,0,0,0,$src_size[0],$src_size[1],$src_size[0],$src_size[1]);
		@ imagealphablending($img,true);

		// load watermark
		$watermark_size=getimagesize($watermark);
		$watermark_img=imagecreatefrompng($watermark);
		@ imagealphablending($wartermark_img,true);

		// apply watermark
		$img=image_overlap($img,$watermark_img);
		imagecopy($img,$watermark_img,0,0,0,0,0,0);

		imagedestroy($src_img);
		imagedestroy($watermark_img);

		switch ($src_format) {
			case "jpg":
				imagejpeg($img,$src,$quality);
				break;
			case "gif":
				imagegif($img,$src);
				break;
			case "bmp":
				imagebmp($img,$src);
				break;
			case "png":
				imagepng($img,$src,$quality);
				break;
		}

		imagedestroy($img);
	} else {
		die("Watermark: Source don't exists -- ".$src);
	}
}

Note:

For BMPs you will need the functions on this post.

Leave a Comment :, , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!