This GDlib Trick let you stack different transparent png Images to one JPG.

<?php

header("Content-Type: image/jpeg");

$image_arr=array('path1.png', 'path2.png', 'path3.png');

$base  = imagecreatetruecolor(913, 500);
$color = imagecolorallocate($base, 255, 255, 255);
imagefill($base, 0, 0, $color);

foreach($image_arr as $key=>$image_val){
    $this_layer=imageCreateFromPNG($image_val);
    ImageCopy ( $base, $this_layer, 0 , 0 , 0 , 0 , 913 , 500 );
}

imagejpeg($base,NULL, 85);
imagedestroy($base);
?>

@public #gdlib #php #image #transform #stack #jpg

Wozu das Ganze?

Wenn man aus mehreren einzelnen Bildern am Ende ein gesamtes Bild erzeugt, dann ist es besser sich nicht auf die Browser zu verlassen und dass diese die übereinander geschichteten Bilder korrekt darstellen.

Statt JPG als PNG ausgeben

public gdlib php image transform stack png transparent php

This GDlib Trick let you stack different transparent png Images to one transparent png.

<?php

$image_arr=array('path1.png', 'path2.png', 'path3.png');
echo gd_gen_image($image_arr);


function gd_gen_image($arr){
    $base  = imagecreatetruecolor(913, 500);
    $color = imagecolorallocatealpha($base, 0, 0, 0, 127);
    imagefill($base, 0, 0, $color);
    imagesavealpha($base, TRUE);

    foreach($arr as $key=>$image_val){
        $this_layer=imageCreateFromPNG($image_val);
        ImageCopy ( $base, $this_layer, 0 , 0 , 0 , 0 , 913 , 500 );
    }

    // Begin capturing the byte stream
    ob_start();
        imagePNG($base);
    $out=ob_get_clean();
    // END capturing the byte stream
    return "<img src='data:image/png;base64," . base64_encode( $out ) . "' />";
}

?>

@public #gdlib #php #image #transform #stack #png #transparent

Statt PNG als JPG ausgeben: http://codebase.webmaster-fragen.de/snippet/public-gdlib-php-image-transform-stack-php/

How to transfer an Array over URL GET Parameters

<?php
/* array_over_get.php */
$image_arr=array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg");
$serial_arr=urlencode(base64_encode(serialize($image_arr)));

echo '<img src="process_images.php?arr='.$serial_arr.'" alt="stacked image"/>';
?>


<?php
/* process_images.php */
$image_arr=unserialize(base64_decode(urldecode($_GET['arr'])));

foreach($image_arr as $value){
   /* do anything here 
    * just as an example
    * https://gist.github.com/vdite/30644e28301916789ff5
    */
}
?>

Why use of base64 encoding? URLencoding on a string is a waste of space and you only have 4k. http://stackoverflow.com/a/8594760/2099411

BUT, base64 encode may have +=/ characters, that have to be translated with urlencode mehr Infos: http://mizine.de/html/array-ueber-get-url-parameter-uebergeben/

@public #array #get #parameter #serialize #php

Projects

Tags

Capsule Servers

Lost connection to server.