<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problema con il resize di immagini]]></title><description><![CDATA[<p dir="auto">Ciao aragazzi, premetto che il php lo uso veramente poco, quindi perdonate eventuali castronerie...</p>
<p dir="auto">vi presento il problema, ho creato uno script per il resize di immagini, lo script funziona alla grande, però non riesco a settare il colore dello sfondo, e tutte le immagini tagliate presentano delle fastidiose bande nere (tipo quelle del 16:9)...</p>
<p dir="auto">Questo è il codice:</p>
<pre><code>

function ResizeProportionalImage($nw, $nh, $source, $stype, $dest="", $ca="", $cb="",$cc=""){
    switch($stype){
            case "stream":
                $simg = imagecreatefromstring($source);
                break;
            case IMAGETYPE_GIF:
                    $simg = imagecreatefromgif($source);
                    break;
                case IMAGETYPE_JPEG:
                    $simg = imagecreatefromjpeg($source);
                        break;
                case IMAGETYPE_PNG:
                    $simg = imagecreatefrompng($source);
                        break;
        }
        $w =  imagesx($simg); 
        $h =  imagesy($simg); 
        
        $dimg = imagecreatetruecolor($nw, $nh);
        imagealphablending($dimg, false);
        //background
        if (!$ca=="" &amp;&amp; !$cb=="" &amp;&amp; !$cc=="") {
            $bg = imagecolorallocate ( $dimg, $ca, $cb, $cc );
            //$bg = imagecolorallocate ( $dimg, 255, 255, 255 );
        }else{
        
            $bg = imagecolorallocate ( $dimg, 255, 255, 255 );
        }
       
  
    if ($w/$h&gt;$nw/$nh){
        $imgTempResize = imagecreatetruecolor($nw, ($h * $nw / $w));
        imagecopyresampled($imgTempResize, $simg, 0, 0, 0, 0, $nw, ($h * $nw / $w), $w, $h);
    }else{
        $imgTempResize = imagecreatetruecolor(($w * $nh / $h), $nh);
        imagecopyresampled($imgTempResize, $simg, 0, 0, 0, 0, ($w * $nh / $h), $nh, $w, $h);
    }
    

    $w = imagesx($imgTempResize);
        $h = imagesy($imgTempResize);
    
    
    $xstart = ($w/2) - ($nw/2);
    $ystart = ($h/2) - ($nh/2);
    $xend = $xstart + $nw;
    $yend = $ystart + $nh;
   
    //CROPPO
    imagecopy($dimg, $imgTempResize, 0,0, $xstart, $ystart, $nw, $nh);
    
        imagecopyresampled($dimg, $imgTempResize, $xend, $yend, 0, 0, $nw, $nh, $w, $h );
    //imagefill ( $dimg, 15, 15, $bg );
        
        if($dest!=?){
            imagejpeg($dimg,$dest,100);
        }else{
            imagejpeg($dimg); 
            //return $dimg;
        }
         imagedestroy($simg);
       imagedestroy($dimg);
         imagedestroy($imgTempResize);
}

</code></pre>
<p dir="auto">come potete vedere ho implementato imagefill (che ora è commentato) però invece di riempirmi tutta l'immagine mi toglie solo una banda (per la cronaca quella a sx dell'immagine)</p>
<p dir="auto">Ringrazio in anticipo coloro che vogliono darmi una mano</p>
<p dir="auto"><img src="https://connect.gt/plugins/nodebb-plugin-emoji/emoji/customizations/54a3bffb-5e4a-4eb8-81dc-99b2072e5d05-175.gif?v=4as8rolt52f" class="not-responsive emoji emoji-customizations emoji--ciauz" title=":ciauz:" alt=":ciauz:" /><img src="https://connect.gt/plugins/nodebb-plugin-emoji/emoji/customizations/54a3bffb-5e4a-4eb8-81dc-99b2072e5d05-175.gif?v=4as8rolt52f" class="not-responsive emoji emoji-customizations emoji--ciauz" title=":ciauz:" alt=":ciauz:" /></p>
]]></description><link>https://connect.gt/topic/43087/problema-con-il-resize-di-immagini</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 04:25:55 GMT</lastBuildDate><atom:link href="https://connect.gt/topic/43087.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Aug 2007 11:22:54 GMT</pubDate><ttl>60</ttl></channel></rss>