<?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[Upload e ridimensionamento immagini]]></title><description><![CDATA[<p dir="auto">Qualcuno mi può aiutare ha modificare questo codice per l'upload delle immagini.</p>
<p dir="auto">Attualmente funziona in questo modo:<br />
Viene ritagliato un quadrato con lato uguale alla lunghezza del lato più corto della foto caricata:<br />
Dopodiché il quadrato viene ridotto a 120x120 pixel e poi salvato nella cartella "foto".</p>
<p dir="auto">E qui mi sono bloccato...</p>
<p dir="auto">Adesso vorrei far si che oltre a salvare la miniatura da 120x120, mi salvasse anche un altra miniatura da 200x200 e poi una copia dell'immagine originale.</p>
<p dir="auto">ES:<br />
L'utente carica una foto con nome: foto.jpg</p>
<p dir="auto">nella cartella foto ritrovo:<br />
foto.jpg (dimensioni originali)<br />
foto_med.jpg (240x240)<br />
foto_sma.jpg (120x120)</p>
<p dir="auto">Potete aiutarmi... Grazie</p>
<p dir="auto">Questo è il codice:<br />
"... se volete provarlo il codice è completo, quindi salvandolo in un file .php e avviandolo da php fuziona"</p>
<pre><code class="language-php">&lt;?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?&gt;
&lt;?php
// upload the file
if ((isset($_POST["submitted_form"])) &amp;&amp; ($_POST["submitted_form"] == "image_upload_form")) {
// file needs to be jpg,gif,bmp,x-png and 4 MB max
if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") &amp;&amp; ($_FILES["image_upload_box"]["size"] &lt; 4000000))
{
// if uploaded image was JPG/JPEG
if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){
$image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was GIF
if($_FILES["image_upload_box"]["type"] == "image/gif"){
$image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
}
// BMP doesn't seem to be supported so remove it form above image type test (reject bmps)
// if uploaded image was BMP
if($_FILES["image_upload_box"]["type"] == "image/bmp"){
$image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was PNG
if($_FILES["image_upload_box"]["type"] == "image/x-png"){
$image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
}
$remote_file = "foto/".$_FILES["image_upload_box"]["name"];
imagejpeg($image_source,$remote_file,80);
chmod($remote_file,0644);
$new_w = 120;
$new_h = 120;
$orig_w = imagesx($image_source);
$orig_h = imagesy($image_source);
 
$w_ratio = ($new_w / $orig_w);
$h_ratio = ($new_h / $orig_h);
// PAESAGGIO
if ($orig_w &gt; $orig_h ) {
$crop_w = round($orig_w * $h_ratio);
$crop_h = $new_h;
$x = ($orig_w - $orig_h) / 2;
 
// RITRATTO
} elseif ($orig_w &lt; $orig_h ) {
$crop_h = round($orig_h * $w_ratio);
$crop_w = $new_w;
$y = ($orig_h - $orig_w) /2;
// QUADRATO
} else {
$crop_w = $new_w;
$crop_h = $new_h;
}
$new_image = imagecreatetruecolor($new_w,$new_h);
$image_source = imagecreatefromjpeg($remote_file);
imagecopyresampled($new_image, $image_source, 0, 0, $x, $y, $crop_w, $crop_h, $orig_w, $orig_h);
imagejpeg($new_image,$remote_file,80);
imagedestroy($new_image);
imagedestroy($image_source);
 
header("Location: submit.php?upload_message=image uploaded&amp;upload_message_type=success&amp;show_image=".$_FILES["image_upload_box"]["name"]);
exit;
}
else{
header("Location: submit.php?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&amp;upload_message_type=error");
exit;
}
}
?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "***************************************"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Image Upload with resize&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
color: #333333;
font-size: 12px;
}
.upload_message_success {
padding:4px;
background-color:#009900;
border:1px solid #006600;
color:#FFFFFF;
margin-top:10px;
margin-bottom:10px;
}
.upload_message_error {
padding:4px;
background-color:#CE0000;
border:1px solid #990000;
color:#FFFFFF;
margin-top:10px;
margin-bottom:10px;
}
--&gt;
&lt;/style&gt;&lt;/head&gt;
&lt;body&gt;
&lt;h1 style="margin-bottom: 0px"&gt;INSERIMENTO IMMAGINE&lt;/h1&gt;
 
&lt;?php if(isset($_REQUEST['upload_message'])){?&gt;
&lt;div class="upload_message_&lt;?php echo $_REQUEST['upload_message_type'];?&gt;"&gt;
&lt;?php echo htmlentities($_REQUEST['upload_message']);?&gt;
&lt;/div&gt;
&lt;?php }?&gt;
 
&lt;form action="submit.php" method="post" enctype="multipart/form-data" name="image_upload_form" id="image_upload_form" style="margin-bottom:0px;"&gt;
&lt;label&gt;- Dimensione massima: 4MB - Estensioni possibili: jpg, gif, png.&lt;/label&gt;&lt;br /&gt;
&lt;input name="image_upload_box" type="file" id="image_upload_box" size="40" /&gt;
&lt;input type="submit" name="submit" value="Upload image" /&gt;
&lt;br /&gt;
&lt;br /&gt;
 
&lt;input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" /&gt;
&lt;/form&gt;
 
 
&lt;?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){?&gt;
&lt;p&gt;
&lt;img src="foto/&lt;?php echo $_REQUEST['show_image'];?&gt;" /&gt;
&lt;/p&gt;
&lt;?php }?&gt;
 
 
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/topic/121255/upload-e-ridimensionamento-immagini</link><generator>RSS for Node</generator><lastBuildDate>Mon, 30 Nov 2026 03:44:12 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/121255.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Feb 2010 18:51:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Wed, 01 Sep 2010 10:14:49 GMT]]></title><description><![CDATA[<p dir="auto">Edit</p>
]]></description><link>https://dev.connect.gt/post/891374</link><guid isPermaLink="true">https://dev.connect.gt/post/891374</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Wed, 01 Sep 2010 10:14:49 GMT</pubDate></item><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Sat, 21 Aug 2010 11:13:51 GMT]]></title><description><![CDATA[<p dir="auto">Rieccomi, mi scuso se rispondo solo ora ma avevo accantonato l'upload delle immagini per dare riorità ad altre parti del progetto...Ho ripreso in mano tutte le prove e i problemi persistono, anche con le ultime modifiche non riesco a risolvere il problema; fino al resize della singola immagine tutto ok, mentre i 2 file che mi hai passato non riesco a farli funzionare.<br />
Ti chiedo gentilmente se quando hai tempo puoi fare un test e vedere se capisci dov'è il problema, io non so più dove sbattere la testa.</p>
<p dir="auto">Grazie</p>
]]></description><link>https://dev.connect.gt/post/891373</link><guid isPermaLink="true">https://dev.connect.gt/post/891373</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Sat, 21 Aug 2010 11:13:51 GMT</pubDate></item><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Sun, 28 Feb 2010 18:31:02 GMT]]></title><description><![CDATA[<p dir="auto">attenzione che la riga 27 ti dice che non trova il file class.image-resize.php quindi controlla bene il percorso se è corretto.</p>
<p dir="auto">poi togli le righe 15, 16 e 17</p>
<p dir="auto">Ciao</p>
]]></description><link>https://dev.connect.gt/post/891378</link><guid isPermaLink="true">https://dev.connect.gt/post/891378</guid><dc:creator><![CDATA[illustre]]></dc:creator><pubDate>Sun, 28 Feb 2010 18:31:02 GMT</pubDate></item><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Sun, 28 Feb 2010 12:54:50 GMT]]></title><description><![CDATA[<p dir="auto">Ho creato le cartelle in questo modo, nella cartella "www" di easyphp ho creato le cartelle:<br />
foto/full<br />
foto/resize_240<br />
foto/resize_120</p>
<p dir="auto">però mi da comunque errore:</p>
<pre><code>[B]Warning[/B]: chmod() [---]: No such file or directory in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]15[/B]
 
[B]Warning[/B]: chmod() [---]: No such file or directory in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]16[/B]
 
[B]Warning[/B]: chmod() [---]: No such file or directory in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]17[/B]
 
[B]Warning[/B]: include(include/class.image-resize.php) [---]: failed to open stream: No such file or directory in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]27[/B]

[B]Warning[/B]: include() [---]: Failed opening 'include/class.image-resize.php' for inclusion (include_path='.;C:\php5\pear') in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]27[/B]

[B]Fatal error[/B]: Class 'img_opt' not found in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]28[/B]
</code></pre>
<p dir="auto">Andando a controllare le cartelle, al loro interno c'è l'immagine che ho caricato, però non ridimensionata.</p>
]]></description><link>https://dev.connect.gt/post/891372</link><guid isPermaLink="true">https://dev.connect.gt/post/891372</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Sun, 28 Feb 2010 12:54:50 GMT</pubDate></item><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Sun, 28 Feb 2010 11:50:17 GMT]]></title><description><![CDATA[<p dir="auto">Ciao</p>
<p dir="auto">si hai ragione, macava qualche cosa.</p>
<p dir="auto">provalo così, io non l'ho provato, attendo alle riche dove vengono definiti i nomi dei 3 file, devi creare le cartelle dove andranno le foto interessate.</p>
<pre><code>&lt;?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?&gt;
&lt;?php
// upload the file
if ((isset($_POST["submitted_form"])) &amp;&amp; ($_POST["submitted_form"] == "image_upload_form")) {
    
// file needs to be jpg,gif,bmp,x-png and 4 MB max
if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") &amp;&amp; ($_FILES["image_upload_box"]["size"] &lt; 4000000))
{

$remote_file_full = "foto/full/".$_FILES["image_upload_box"]["name"];
$remote_file_240 = "foto/resize_240/".$_FILES["image_upload_box"]["name"];
$remote_file_120 = "foto/resize_120/".$_FILES["image_upload_box"]["name"];


chmod($remote_file_full,0644);
chmod($remote_file_240,0644);
chmod($remote_file_120,0644);

// carico la foto originale
move_uploaded_file($_FILES['image_upload_box']['tmp_name'], $remote_file_full);
copy($remote_file_full,$remote_file_240);
copy($remote_file_full,$remote_file_120);


                // procedo a ridimensionare la foto per 240 e per 120

                include("include/class.image-resize.php");
                $obj = new img_opt();
                $obj-&gt;max_width(240);
                $obj-&gt;max_height(240);
                $obj-&gt;image_path($remote_file_240);
                $obj-&gt;image_resize();
                
                $obj2 = new img_opt();
                $obj2-&gt;max_width(120);
                $obj2-&gt;max_width(120);
                $obj2-&gt;image_path($remote_file_120);
                $obj2-&gt;image_resize();
 
header("Location: submit.php?upload_message=image uploaded&amp;upload_message_type=success&amp;show_image=".$_FILES["image_upload_box"]["name"]);
exit;
 } else{
header("Location: submit.php?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&amp;upload_message_type=error");
exit;
}
}
?&gt;
</code></pre>
<p dir="auto">fammi sapere</p>
<p dir="auto">ciao</p>
]]></description><link>https://dev.connect.gt/post/891377</link><guid isPermaLink="true">https://dev.connect.gt/post/891377</guid><dc:creator><![CDATA[illustre]]></dc:creator><pubDate>Sun, 28 Feb 2010 11:50:17 GMT</pubDate></item><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Sun, 28 Feb 2010 10:41:49 GMT]]></title><description><![CDATA[<p dir="auto">Grazie per l'aiuto, l'ho provato però mi restituisce questi errori e non capisco il motivo:</p>
<p dir="auto"><strong>```</strong><br />
<strong>[/B]</strong><br />
<strong>[B]Warning[/B]: chmod() : No such file or directory in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]11[/B]</strong></p>
<p dir="auto"><strong>[B]Warning[/B]: include(include/class.image-resize.php) [...]: failed to open stream: No such file or directory in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]19[/B]</strong></p>
<p dir="auto"><strong>[B]Warning[/B]: include() [...]: Failed opening 'include/class.image-resize.php' for inclusion (include_path='.;C:\php5\pear') in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]19[/B]</strong></p>
<p dir="auto"><strong>[B]Fatal error[/B]: Class 'img_opt' not found in [B]C:\Program Files (x86)\EasyPHP-5.3.1\www\submit.php[/B] on line [B]20[/B]</strong><br />
<strong>[B]</strong><br />
<strong>```</strong></p>
]]></description><link>https://dev.connect.gt/post/891371</link><guid isPermaLink="true">https://dev.connect.gt/post/891371</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Sun, 28 Feb 2010 10:41:49 GMT</pubDate></item><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Sun, 28 Feb 2010 04:58:37 GMT]]></title><description><![CDATA[<p dir="auto">Ciao</p>
<p dir="auto">ti allego solo parte php, è una soluzione diversa a quello che hai tu nel codice.<br />
Questo ti salva la foto in originale, ti crea 2 resize, uno da 120 e uno da 240 come hai specificato.</p>
<p dir="auto">P.S. non ho testato il codice che ti allego.</p>
<hr />
<pre><code>&lt;?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?&gt;
&lt;?php
// upload the file
if ((isset($_POST["submitted_form"])) &amp;&amp; ($_POST["submitted_form"] == "image_upload_form")) {
    
// file needs to be jpg,gif,bmp,x-png and 4 MB max
if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") &amp;&amp; ($_FILES["image_upload_box"]["size"] &lt; 4000000))
{

$remote_file = "foto/".$_FILES["image_upload_box"]["name"];
chmod($remote_file,0644);

// carico la foto originale
move_uploaded_file($_FILES['image_upload_box']['tmp_name'], $remote_file);


                // procedo a ridimensionare la foto per 240 e per 120

                include("include/class.image-resize.php");
                $obj = new img_opt();
                $obj-&gt;max_width(240);
                $obj-&gt;max_height(240);
                $obj-&gt;image_path($remote_file);
                $obj-&gt;image_resize();
                
                $obj2 = new img_opt();
                $obj2-&gt;max_width(120);
                $obj2-&gt;max_width(120);
                $obj2-&gt;image_path($remote_file);
                $obj2-&gt;image_resize();
 
header("Location: submit.php?upload_message=image uploaded&amp;upload_message_type=success&amp;show_image=".$_FILES["image_upload_box"]["name"]);
exit;
 } else{
header("Location: submit.php?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&amp;upload_message_type=error");
exit;
}
}
?&gt;
</code></pre>
<p dir="auto">questa è la classe utilizzata per il resize (class.image-resize.php).</p>
<pre><code>&lt;?PHP
class img_opt
{
var $max_width;
var $max_height;
var $path;
var $img;
var $new_width;
var $new_height;
var $mime;
var $image;
var $width;
var $height;
    function max_width($width)
    {
        $this-&gt;max_width = $width;
    }
    function max_height($height)
    {
        $this-&gt;max_height = $height;
    }
    function image_path($path)
    {
        $this-&gt;path = $path;
    }
    function get_mime()
    {
        $img_data = getimagesize($this-&gt;path);
        $this-&gt;mime = $img_data['mime'];
    }
    function create_image()
    {
        switch($this-&gt;mime)
        {
            case 'image/jpeg':
                $this-&gt;image = imagecreatefromjpeg($this-&gt;path);
            break;
            
            case 'image/gif':
                $this-&gt;image = imagecreatefromgif($this-&gt;path);
            break;
            
            case 'image/png':
                $this-&gt;image = imagecreatefrompng($this-&gt;path);
            break;
        }
    }    
    function image_resize()
        {
                set_time_limit(120);
                $this-&gt;get_mime();
                $this-&gt;create_image();
                $this-&gt;width = imagesx($this-&gt;image);
                $this-&gt;height = imagesy($this-&gt;image);
                $this-&gt;set_dimension();
                $image_resized = imagecreatetruecolor($this-&gt;new_width,$this-&gt;new_height);
                imagecopyresampled($image_resized, $this-&gt;image, 0, 0, 0, 0, $this-&gt;new_width, $this-&gt;new_height,$this-&gt;width, $this-&gt;height);
                imagejpeg($image_resized,$this-&gt;path);
                        
        }
        
        //######### FUNCTION FOR RESETTING DEMENSIONS OF IMAGE ###########
        function set_dimension()
        {
                
                if($this-&gt;width==$this-&gt;height)
                {
                    $case = 'first';
                }
                elseif($this-&gt;width &gt; $this-&gt;height)
                {
                    $case = 'second';
                }
                else
                {
                     $case = 'third'; 
                }
                
                
                
                if($this-&gt;width&gt;$this-&gt;max_width &amp;&amp; $this-&gt;height&gt;$this-&gt;max_height)
                {
                    $cond = 'first';
                }
                elseif($this-&gt;width&gt;$this-&gt;max_width &amp;&amp; $this-&gt;height&lt;=$this-&gt;max_height)
                {
                    $cond = 'first';
                }
                else
                {
                    $cond = 'third';
                }
                                
                switch($case)
                {
                    case 'first':
                        $this-&gt;new_width = $this-&gt;max_width;
                        $this-&gt;new_height = $this-&gt;max_height;
                    break;
                    case 'second':
                        $ratio = $this-&gt;width/$this-&gt;height;
                        $amount = $this-&gt;width - $this-&gt;max_width;
                        $this-&gt;new_width = $this-&gt;width - $amount;
                        $this-&gt;new_height = $this-&gt;height - ($amount/$ratio);
                    break;
                    case 'third':
                        $ratio = $this-&gt;height/$this-&gt;width;
                        $amount = $this-&gt;height - $this-&gt;max_height;
                        $this-&gt;new_height = $this-&gt;height - $amount;
                        $this-&gt;new_width = $this-&gt;width - ($amount/$ratio);
                    break;
                } 
                    
        }
}



?&gt;
</code></pre>
<p dir="auto">ciao</p>
]]></description><link>https://dev.connect.gt/post/891376</link><guid isPermaLink="true">https://dev.connect.gt/post/891376</guid><dc:creator><![CDATA[illustre]]></dc:creator><pubDate>Sun, 28 Feb 2010 04:58:37 GMT</pubDate></item><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Sun, 21 Feb 2010 12:45:43 GMT]]></title><description><![CDATA[<p dir="auto">C'è nessuno che può darmi una mano, sono completamente bloccato... <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61e.png?v=2190ae3dadd" class="not-responsive emoji emoji-android emoji--disappointed" style="height:1.4em;width:auto;vertical-align:middle" title=":(" alt="😞" /></p>
]]></description><link>https://dev.connect.gt/post/891370</link><guid isPermaLink="true">https://dev.connect.gt/post/891370</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Sun, 21 Feb 2010 12:45:43 GMT</pubDate></item><item><title><![CDATA[Reply to Upload e ridimensionamento immagini on Tue, 16 Feb 2010 11:38:29 GMT]]></title><description><![CDATA[<p dir="auto">Nessuno?</p>
]]></description><link>https://dev.connect.gt/post/891375</link><guid isPermaLink="true">https://dev.connect.gt/post/891375</guid><dc:creator><![CDATA[darkf3d3]]></dc:creator><pubDate>Tue, 16 Feb 2010 11:38:29 GMT</pubDate></item></channel></rss>