Codice PHP:
<?php
require("globals.inc");
header ("Content-type: image/jpeg");
if(!file_exists($img_path))
{
$im = imagecreatetruecolor($w, $h);
$bg = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 2, 20, 10, "Non disponibile", $bg);
imagejpeg($im, "", 100);
imagedestroy($im);
}
else
{
$cachedpath = getCachedPath($img_path, $w, $h);
if(!file_exists($cachedpath))
{
ResizeImage($img_path, $w, $h, true);
}
$source = ImageCreateFromJPEG($cachedpath);
imagejpeg($source, "", 80);
imagedestroy($source);
}
//ResizeImage("public/temp.jpg", 20, 20, true);
function ResizeImage($filename, $th_width, $th_height, $forcefill)
{
global $_repository;
list($width, $height) = getimagesize($filename);
if(substr($filename, strlen($filename) - 3, 3) == "jpg")
$source = ImageCreateFromJPEG($filename);
if(substr($filename, strlen($filename) - 3, 3) == "gif")
$source = ImageCreateFromGIF($filename);
if(substr($filename, strlen($filename) - 3, 3) == "png")
$source = ImageCreateFromPNG($filename);
if($width > $th_width || $height > $th_height)
{
$a = $th_width/$th_height;
$b = $width/$height;
if(($a > $b)^$forcefill)
{
$src_rect_width = $a * $height;
$src_rect_height = $height;
if(!$forcefill)
{
$src_rect_width = $width;
$th_width = $th_height/$height*$width;
}
}
else
{
$src_rect_height = $width/$a;
$src_rect_width = $width;
if(!$forcefill)
{
$src_rect_height = $height;
$th_height = $th_width/$width*$height;
}
}
$src_rect_xoffset = ($width - $src_rect_width)/2*intval($forcefill);
$src_rect_yoffset = ($height - $src_rect_height)/2*intval($forcefill);
$thumb = imagecreatetruecolor($th_width, $th_height);
imagecopyresampled($thumb, $source, 0, 0, $src_rect_xoffset, $src_rect_yoffset, $th_width, $th_height, $src_rect_width, $src_rect_height);
$cachedpath = getCachedPath($filename, $th_width, $th_height);
imagejpeg($thumb, $cachedpath, 80);
imagedestroy($thumb);
}
else
{
imagejpeg( $source,"", 80);
imagedestroy($source);
}
}
function getCachedPath($filename, $w, $h)
{
global $_repository;
$encodedname = urlencode($filename) . "§" . $w . "_" . $h;
$cachedpath = $_repository . "/" . $encodedname;
return $cachedpath;
}
?>
Non so se la soluzione al problema puo essere nascosta nei warning... io ho pensato subito ad una questione di permessi e basta... sono molto confuso dal fatto che alcune foto funzionano e altre no... bhoo