Hallo,
Ik wil voor een wisselende fotoheader een php scriptje gebruiken, ik heb als test nu het volgende geprobeerd:


<?php
$x = '1007';
$y = '277';

$final_img = imagecreate($x, $y); // where x and y are the dimensions of the final image

$image_1 = imagecreatefrompng('zwart.png');
$image_2 = imagecreatefrompng('achter.png');
$image_3 = imagecreatefrompng('voor.png');

imagecopy($image_1, $final_img, 0, 0, 0, 0, $x, $y);
imagecopy($image_2, $final_img, 0, 0, 0, 0, $x, $y);
imagecopy($image_3, $final_img, 0, 0, 0, 0, $x, $y);

imagealphablending($final_img, false);
imagesavealpha($final_img, true);
header('Content-Type: image/png');
imagepng($final_img);

?>


dit komt van het onderste voorbeeld op http://stackoverflow.com/questions/1397377/combine-2-3-transparent-png-images-on-top-of-each-other-with-php

ook dit lukt niet:

<?php
 # If you don't know the type of image you are using as your originals.
 $image = imagecreatefromstring(file_get_contents('achter.png'));
 $frame = imagecreatefromstring(file_get_contents('voor.png'));

 # If you know your originals are of type PNG.
 $image = imagecreatefrompng('voor.png');
 $frame = imagecreatefrompng('achter.png');
imagealphablending($frame,true);
imagealphablending($image,true);
 imagecopymerge($image, $frame, 0, 0, 0, 0, 50, 50, 100);

 # Save the image to a file
 //imagepng($image, '/path/to/save/image.png');

 # Output straight to the browser.
 
header('Content-Type: image/png');
 imagepng($image);
 ?>


(komt van: http://stackoverflow.com/questions/1394061/how-to-merge-transparent-png-with-image-using-php )

Ik heb ook al iets met imagick geprobeerd die dit schijnt te kunnen, maar bij de imagecombine functie staat geen voorbeeld code, maar als iemand wel snapt hoe dat moet, mag het ook... (http://nl.php.net/manual/en/function.imagick-combineimages.php) de enige waarde die je kunt meegeven is namelijk een kleuren chanell ofzo, maar niet welke plaatjes je wilt combinen. je kunt dus wel eerst de classen aanroepen met new, en dan nummer 2 en 3 als input geven aan de functie addImages, maar ook dat lijkt niet te werken:


<?php

$image = new Imagick('zwart.png');
$image2 = new Imagick('voor.png');
$image3 = new Imagick('achter.png');
$image->addImage($image2);
$image->addImage($image3);
$image->CombineImages(9999);
header('Content-Type: image/png');
echo $image;
?>
iemand?

[size=xsmall]Toevoeging op 16/10/2010 13:49:15:[/size]

gelukt met de volgende code :D


<?php
 
 
 function watermark($sourcefile, $watermarkfile) {
  
    #
    # $sourcefile = Filename of the picture to be watermarked.
    # $watermarkfile = Filename of the 24-bit PNG watermark file.
    #
    
    //Get the resource ids of the pictures
    $watermarkfile_id = imagecreatefrompng($watermarkfile);
    
    imageAlphaBlending($watermarkfile_id, false);
    imageSaveAlpha($watermarkfile_id, true);

    $fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));

    switch($fileType) {
        case('gif'):
            $sourcefile_id = imagecreatefromgif($sourcefile);
            break;
            
        case('png'):
            $sourcefile_id = imagecreatefrompng($sourcefile);
            break;
            
        default:
            $sourcefile_id = imagecreatefromjpeg($sourcefile);
    }

    //Get the sizes of both pix   
  $sourcefile_width=imageSX($sourcefile_id);
  $sourcefile_height=imageSY($sourcefile_id);
  $watermarkfile_width=imageSX($watermarkfile_id);
  $watermarkfile_height=imageSY($watermarkfile_id);

    $dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
    $dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
    
    // if a gif, we have to upsample it to a truecolor image
    if($fileType == 'gif') {
        // create an empty truecolor container
        $tempimage = imagecreatetruecolor($sourcefile_width,
                                                                            $sourcefile_height);
        
        // copy the 8-bit gif into the truecolor image
        imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, 
                            $sourcefile_width, $sourcefile_height);
        
        // copy the source_id int
        $sourcefile_id = $tempimage;
    }

    imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,
                        $watermarkfile_width, $watermarkfile_height);

    //Create a jpeg out of the modified picture
    switch($fileType) {
    
        // remember we don't need gif any more, so we use only png or jpeg.
        // See the upsaple code immediately above to see how we handle gifs
        case('png'):
            header("Content-type: image/png");
            imagepng ($sourcefile_id);
            break;
            
        default:
            header("Content-type: image/jpg");
            imagejpeg ($sourcefile_id);
    }           
  
    imagedestroy($sourcefile_id);
    imagedestroy($watermarkfile_id);
    
}
 
echo watermark('achter.png','voor.png');
?>

Reageren