开发者

Combine 2 png-24 transparent Images using Php

开发者 https://www.devze.com 2023-01-31 17:25 出处:网络
Hello I am trying to combine two transparent png-24 images, both size 400width, 150height. A background: [\"http://www.fenixflame.net/Background-Zanaris-24.png\"][1]

Hello I am trying to combine two transparent png-24 images, both size 400width, 150height.

A background: ["http://www.fenixflame.net/Background-Zanaris-24.png"][1]

And the image I want to overlay adobe the background: ["http://www.fenixflame.net/Bandos-Slayer-24.png"][2]

I've tryed overlaying transparent images using php but only png-8 images. Can't use png-8 beacause the images just don't render correctly.

Edit: Code I've tryed:

    $image = imagecreatefrompng("http://www.fenixflame.net/Background-Zanaris-24.png");  
$frame = imagecreatefrompng("http://www.fenixflame.net/Bandos-Slayer-24.png");
//
//imagealphablending($frame,true);
//
 $insert_x = imagesx($frame); 
  $insert_y = imagesy($frame); 
  imagecopymerge($image,$frame,0,0,0,0,$insert_x,$insert_y,100); 
//
//# Save the image to a file imagepng($image, '/path/to/save/image.png');
 imagepng($image, "/home1/fenixfl开发者_运维问答a/public_html/Images/Signatures/NewImageBG.png");
//
//# Output straight to the browser.
 imagepng($image); 
//


I have write a small example to merge two transparent image in this link scitam.com

try this code it works fine.


    $width = 200;
    $height = 200;

    $base_image = imagecreatefromjpeg("base.jpg");
    $top_image = imagecreatefrompng("top.png");
    $merged_image = "merged.png";

    imagesavealpha($top_image, true);
    imagealphablending($top_image, true);

    imagecopy($base_image, $top_image, 0, 0, 0, 0, $width, $height);
    imagepng($base_image, $merged_image);


Use GD Library to render the image and output it in php. http://www.php.net/manual/en/ref.image.php

It gets pretty hairy after that. You have to use start doing things like

imagealphablending($image, false);
imagesavealpha($image, true);

and so on to make sure transparency is correct.

you can see an example of what I did for a client way back on their front page here. It was super tedious and a huge pain. Have fun


How about using lib ImageMagick composite (http://www.imagemagick.org/script/composite.php)

   function composite() {
      $command = "/usr/local/bin/composite [... your properties...]";
      exec($command, $output, $result);
      return ($result == 0 && $output[0] == "");
   }


You might want to check this out: http://php.net/manual/en/function.imagecopymerge.php

The imagecopymerge function is part of the PHP GD library.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号