Lige en hurtig rettelse. Har lige optimeret koden en lille smule, så den også tjekker om filen eksisterer, før den returnerer noget.
<?php
function IconizeImage($imgBack) {
if (file_exists($imgBack)) {
header("Content-type: image/jpeg");
$imgIcon = imagecreatefrompng('picgen_icon.png');
$imgX = imagesx($imgIcon);
$imgY = imagesy($imgIcon);
// imagealphablending($imgBack, 1);
list($width, $height, $type, $attr) = getimagesize("$imgBack");
//Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM.
switch($type) {
case 1:
$imgBack = imagecreatefromgif($imgBack);
break;
case 2:
$imgBack = imagecreatefromjpeg($imgBack);
break;
case 3:
$imgBack = imagecreatefrompng($imgBack);
break;
}
imagecopy($imgBack, $imgIcon, 0, 0, 0, 0, $imgX, $imgY);
imagejpeg($imgBack);
imagedestroy($imgBack);
imagedestroy($imgIcon);
}
else {
echo "Filen eksisterer ikke";
}
}
$picture = $_GET['pic'];
IconizeImage($picture);
?>
Mvh. Emilbp