note 84288 added to function.imagefill

From: Date: Tue, 08 Jul 2008 02:27:06 +0000
Subject: note 84288 added to function.imagefill
Groups: php.notes 
Request: Send a blank email to php-notes+get-141254@lists.php.net to get a copy of this message
I've used razonklnbd's example, I had to fill an image with a background pattern from an image (file). So I put the code to pieces and come up with a lighter version that suited me, all thanks to razonklnbd. My version receives three parameters, $image, $width, $height. $image = The background pattern image $width = Width of the new image $height = Height of the new image <?php function imagefillfromfile($image, $width, $height) { $imageWidth = imagesx($image); $imageHeight = imagesy($image); $newImage = imagecreatetruecolor($width, $height); for ($imageX = 0; $imageX < $width; $imageX += $imageWidth) { for ($imageY = 0; $imageY < $height; $imageY += $imageHeight) { imagecopy($newImage, $image, $imageX, $imageY, 0, 0, $imageWidth, $imageHeight); } } return($newImage); imagedestroy($newImage); } ?> This function returns a new image with a filled canvas of an image (file) with a fixed width/height. Example usage: <?php $pattern = imagecreatefrompng('pattern.png'); $image = imagefillfromfile($pattern, 400, 300); imagepng($image); imagedestroy($image); imagedestroy($pattern); ?> ---- Server IP: 80.67.2.2 Probable Submitter: 85.224.85.52 ---- Manual Page -- http://www.php.net/manual/en/function.imagefill.php Edit -- https://master.php.net/note/edit/84288 Del: integrated -- https://master.php.net/note/delete/84288/integrated Del: useless -- https://master.php.net/note/delete/84288/useless Del: bad code -- https://master.php.net/note/delete/84288/bad+code Del: spam -- https://master.php.net/note/delete/84288/spam Del: non-english -- https://master.php.net/note/delete/84288/non-english Del: in docs -- https://master.php.net/note/delete/84288/in+docs Del: other reasons-- https://master.php.net/note/delete/84288 Reject -- https://master.php.net/note/reject/84288 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#141254) next »