php - Merge two images with GD Library, have 1 repeat in background -


i want take image has transparency , overlay on top of 60x60 (arbitrary size) image repeats width , length of first image...

so use image 2 repeating background image image 1 on top of.

edit:

okay, used 1 trick pony's solution, tried modify create square image out of rectangle if width less height, not stretch original image , instead center it. able center image repeating background not continue repeating after overlay image stops.

here code:

    <?php      $overlay    = imagecreatefrompng('../images/' . $_request['overlay']);      $repeating  = '../images/' . $_request['repeating'];     $ext = explode('.', $_request['repeating']);     $ext = strtolower($ext[1]);       if ($ext == 'gif')         $repeating  = imagecreatefromgif($repeating);     elseif ($ext == 'png')         $repeating  = imagecreatefrompng($repeating);     elseif ($ext == 'jpg' || $ext == 'jpeg')         $repeating  = imagecreatefromjpeg($repeating);       $w          = imagesx($overlay);     $h          = imagesy($overlay);     if ($w < $h)          $w = $h;      $output = imagecreatetruecolor($w, $h);     imagealphablending($output, true);       imagesettile($output, $repeating);     imagefill($output, 0, 0, img_color_tiled);     imagedestroy($repeating);          $offsetx = ($w - imagesx($overlay)) / 2;      imagecopy($output, $overlay, $offsetx, 0, 0, 0, $w, $h);     imagedestroy($overlay);       header('content-type: image/png');     imagepng($output);     imagedestroy($output);        ?> 

edit 2:

overlay: http://72.167.52.68/~viisi/ebaylist/images/back_test2.png

repeating: http://72.167.52.68/~viisi/ebaylist/images/back_test.gif

expected result (but continue repeating across whole image): http://72.167.52.68/~viisi/ebaylist/image/previewimage.php?overlay=back_test2.png&repeating=back_test.gif

$overlay = imagecreatefrompng('/path/to/transparent/image.png'); $repeating = imagecreatefrompng('/path/to/repeating/image.png');  // create new image matching overlay size $w = imagesx($overlay); $h = imagesy($overlay); $output = imagecreatetruecolor($w, $h); imagealphablending($output, true); imagesavealpha($output, true);  // tile repeating image on imagesettile($output, $repeating); imagefill($output, 0, 0, img_color_tiled); imagedestroy($repeating);      // add overlay on top imagecopy($output, $overlay, 0, 0, 0, 0, $w, $h); imagedestroy($overlay);  // send screen header('content-type: image/png'); imagepng($output); imagedestroy($output); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -