Io ho fatto qualcosa di simile:
Codice PHP:
<?php
header('Content-Type: image/jpeg');
$bordo = 4;
$percorso = "../../IMG/";
$w = $_REQUEST["w"];
$h = $_REQUEST["h"];
$img = $_REQUEST["img"];
//immagine che farà da bordo + sfondo -->dimensioni $w $h
$im1 = @imagecreatetruecolor($w, $h)
or die("Cannot Initialize new JPG image stream");
imagefilledrectangle($im1, 0, 0, $w, $h, imagecolorallocate($im1, 156, 180, 201));
imagefilledrectangle($im1, $bordo-1, $bordo-1, $w-($bordo), $h-($bordo), imagecolorallocate($im1, 255, 255, 255));
$photoImage = $im1;
$sourcefile = $percorso.$img;
$jpegqual = 100;
// Get the dimensions of the source picture
$picsize=getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];
$dest_y = $h - (2*$bordo); // nel caso di ==
$dest_x = round(($dest_y * $source_x) / $source_y);// nel caso di ==
if (($source_x / $source_y) < ($w / $h)){
$dest_y = $h - (2*$bordo);
$dest_x = round(($dest_y * $source_x) / $source_y);
}else{
$dest_x = $w - (2*$bordo);
$dest_y = round(($dest_x * $source_y) / $source_x);
}
switch ($picsize[2]){
case 1: //gif
$source_id = imageCreateFromGIF("$sourcefile");
break;
case 2: //jpeg
$source_id = imageCreateFromJPEG("$sourcefile");
break;
case 3: // png
$source_id = imageCreateFromPNG("$sourcefile");
break;
case 4: //swf
;//errore
break;
case 5: //psd
;//errore
break;
case 6: //bmp
$source_id = imagecreatefromwbmp("$sourcefile");
break;
case 7: //TIFF_II (intel byte order)
;//errore
break;
case 8: //TIFF_MM (motorola byte order)
;//errore
break;
case 9: //jpc
;//errore
break;
case 10: //jp2
;//errore
break;
case 11: //jpx
;//errore
break;
case 12: //jb2
;//errore
break;
case 13: //swc
;//errore
break;
case 14: //iff
;//errore
break;
case 15: //wbmp
;//errore
break;
case 16: //xbm
;//errore
break;
default:
$source_id = imageCreateFromJPEG("$sourcefile");//vado a muzzo e gli faccio generare l'errore...
}
// Create a new image object (not neccessarily true colour)
$target_id=imagecreatetruecolor($dest_x, $dest_y);
// Resize the original picture and copy it into the just created image
// object. Because of the lack of space I had to wrap the parameters to
// several lines. I recommend putting them in one line in order keep your
// code clean and readable
$target_pic=imagecopyresampled($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y);
// Create a jpeg with the quality of "$jpegqual" out of the
// image object "$target_pic".
// This will be saved as $targetfile
$imgFinale = $target_id;
$posX = round(($w - $dest_x)/2);
$posY = round(($h - $dest_y)/2);
//unisco lo sfondo bordato e la fotografia -->dimensione $w $h
$targetfile = $percorso."show_".$img;
$jpegqual = 100;
ImageAlphaBlending($photoImage, true);
$logoImage = $imgFinale;
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
ImageCopy($photoImage, $logoImage, $posX, $posY, 0, 0, $logoW, $logoH);
ImageJPEG($photoImage);
imagedestroy($photoImage);
imagedestroy($logoImage);
imagedestroy($im1);
imagedestroy($im2);
imagedestroy($target_id);
imagedestroy($source_id);
?>
Spiego un po':
tu metti questo codice in una pagina (image.php per esempio)
quando devi stampare a video un'immagine fai così:
[img]image.php?w=<? echo $w; ?>&h=<? echo $h; ?>&img=<? echo $img; ?>[/img]" height="<? echo $h; ?>">
dove $w è la larghezza, $h l'altezza e $img il nome dell'immagine
In pratica ridimensiona l'immagine sorgente in modo da farcela stare in un'altra immagine delle dimesnioni che desideri tu, aggiungendo anche un bordo.
Modificando il codice puoi ottenere quello che vuoi.
Potrebbero esserci dei bug in quanto il metodo che uso lo sto sperimentando e quindi è ancora in costante aggiornamento, cmq lo sto usando e funziona correttamente.