PHP 8.5.0 Alpha 1 available for testing

Voting

: max(two, six)?
(Example: nine)

The Note You're Voting On

razonklnbd at yahoo dot com
18 years ago
I spend more then two hour to find a function that can fill a pattern or file as background instead of color. but i can't find. so i develop the following function. i though this function will save time who need it...

Function will get four parameter
1. Main Image Identifier
2. Pattern Image Identifier
3. Final Image Width
4. Final Image Height

If you set final image width or height is less then main image width or height then you may get wrong result

<?php

function fill_with_patternfile($p_main_im, $p_patternfile_im, $p_width, $p_height){
$pimiX=$p_patternfile_im;
$pw=imagesx($pimiX);
$ph=imagesy($pimiX);
$targetImageIdentifier=imagecreatetruecolor($p_width,$p_height);
if(
$pw<$p_width && $ph<$p_height){
for(
$pX=0;$pX<$p_width;$pX+=$pw){
for(
$pY=0;$pY<$p_height;$pY+=$ph){
imagecopy($targetImageIdentifier,$pimiX,$pX,$pY,0,0,$pw,$ph);
}
}
}else
imagecopy($targetImageIdentifier,$pimiX,0,0,0,0,$pw,$ph);
$w=imagesx($p_main_im);
$h=imagesy($p_main_im);
$nX=0;
if(
$w<$p_width) $nX=intval(($p_width-$w)/2);
$nY=0;
if(
$h<$p_height) $nY=intval(($p_height-$h)/2);
imagecopy($targetImageIdentifier,$p_main_im,$nX,$nY,0,0,$w,$h);
return
$targetImageIdentifier;
}
// If you want to use a gif or png file as
// pattern file you need to change function below :)
$pattern_im=imagecreatefromjpeg('logo.jpg');
// If you want to use a gif or png file as
// main file you need to change function below :)
$main_im=imagecreatefromjpeg('r2.jpg');
// call the function width 500 and height 500
// if your width and height is less then main images
// width and height then you can't understand any change!
$final=fill_with_patternfile($main_im, $pattern_im, 500, 500);
// view the image and destroy all instance
header('Content-type: image/jpeg');
imagejpeg($final);
imagedestroy($final);
imagedestroy($main_im);
imagedestroy($pattern_im);
exit();

?>

<< Back to user notes page

To Top