<?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[Php Thumbnail e watermark]]></title><description><![CDATA[<p dir="auto">Salve ragazzi, ho realizzato da poco un sito web per una agenzia immobiliare, nel pannello di amministrazione dove vengono caricati gli immobili vengono caricate le foto relative ad ogni singolo immobile. Le foto hanno una dimenzione 400x300 px e vanno benissimo nelle pagine del dettaglio ma nelle pagine elenco dove ho il campo immagine 120x80 mi sembra inutile caricare una foto 400x300 e ridimenzionarla solo virtualmente. A questo punto avrei bisogno di uno script php per le Thumbnail e per il watermark.</p>
<p dir="auto">Quello che in pratica cerco di fare è creare le Thumbnail che andranno a finire in una cartella che chiamerò "small" mentre le foto con dimensione superiore e con watermark andranno nella cartella principale "image" tutto questo gestito dal pannello di controllo.</p>
<p dir="auto">Secondo Voi come potreei risolvere il problema? Qualcuno di Voi ha fatto qualcosa di simile?<br />
Grazie anticipatamente <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/8dfea2c6-baa4-48ad-9022-ab237b734846-fumato5.gif?v=2190ae3dadd" class="not-responsive emoji emoji-customizations emoji--fumato" style="height:1.4em;width:auto;vertical-align:middle" title=":fumato:" alt="" /></p>
]]></description><link>https://dev.connect.gt/topic/97015/php-thumbnail-e-watermark</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Dec 2026 05:02:03 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/97015.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Mar 2009 10:50:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Php Thumbnail e watermark on Sat, 14 Mar 2009 09:13:22 GMT]]></title><description><![CDATA[<p dir="auto">To utilizzando uno script trovato in rete e devo dire che funziona <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/1881713c-5c09-4986-bf15-fa308ef84b2e-smilegt.gif?v=2190ae3dadd" class="not-responsive emoji emoji-customizations emoji--smile5" style="height:1.4em;width:auto;vertical-align:middle" title=":smile5:" alt="" /><br />
<strong>questa è la classe:</strong><br />
&lt;?php</p>
<p dir="auto">/**</p>
<ul>
<li>Smart, easy and simple Image Manipulation</li>
<li></li>
<li>@author Alessandro Coscia, Milano, Italy,</li>
<li>codicefacile. it/ smartimage</li>
<li>@copyright LGPL</li>
<li>@version 0.9.6</li>
<li></li>
</ul>
<p dir="auto"><em>/<br />
class SmartImage {<br />
/</em>*<br />
* Source file (path)<br />
*/<br />
private $src;</p>
<pre><code>/**
 * GD image's identifier
 */
private $gdID;

/**
 * Image info
 */
private $info;

/**
 * Initialize image
 *
 * @param string $src
</code></pre>
<ul>
<li>@param boolean $big
<ul>
<li><a class="plugin-mentions-user plugin-mentions-a" href="/user/return" aria-label="Profile: return">@<bdi>return</bdi></a> SmartImage<br />
*/<br />
public function SmartImage($src, $bigImageSize=false) {<br />
// In case of very big images (more than 1Mb)<br />
if ($bigImageSize)<br />
$this-&gt;setMemoryForBigImage($src);</li>
</ul>
</li>
</ul>
<pre><code>// set data
$this-&gt;src = $src;
$this-&gt;info = getimagesize($src);

// open file
if ( $this-&gt;info[2] == 2 )        $this-&gt;gdID = imagecreatefromjpeg($this-&gt;src);
elseif ( $this-&gt;info[2] == 1 )    $this-&gt;gdID = imagecreatefromgif($this-&gt;src);
elseif ( $this-&gt;info[2] == 3 )     $this-&gt;gdID = imagecreatefrompng($this-&gt;src);

}
</code></pre>
<p dir="auto">/**</p>
<ul>
<li>
<p dir="auto">Set memory in case of very big images (more than 1Mb)</p>
</li>
<li>
<p dir="auto">new SmartImage($src, true) to activate this function</p>
</li>
<li>
<p dir="auto">Works with (PHP 4 &gt;= 4.3.2, PHP 5) if compiled with --enable-memory-limit</p>
</li>
<li>
<p dir="auto">or PHP&gt;=5.2.1</p>
</li>
<li>
<p dir="auto">Thanks to Andrvm and to Bascunan for this feature<br />
*/<br />
private function setMemoryForBigImage($filename) {<br />
$imageInfo    = getimagesize($filename);<br />
$memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);</p>
<p dir="auto">$memoryLimit = (int) ini_get('memory_limit')*1048576;</p>
<p dir="auto">if ((memory_get_usage() + $memoryNeeded) &gt; $memoryLimit) {<br />
ini_set('memory_limit', ceil((memory_get_usage() + $memoryNeeded + $memoryLimit)/1048576).'M');<br />
return (true);<br />
}<br />
else return(false);<br />
}</p>
</li>
</ul>
<pre><code>/**
 * Resize an image
 *
 * @param integer $w
 * @param integer $h
 * @param boolean $cutImage
 * @return boolean Everything is ok?
 */
public function resize($width, $height, $cutImage = false) {
    if ($cutImage)
    return $this-&gt;resizeWithCut($width, $height);
    else
    return $this-&gt;resizeNormal($width, $height);
}

/**
 * Resize an image without cutting it, only do resize
 * saving proportions and adapt it to the smaller dimension
 *
 * @param integer $w
 * @param integer $h
 */
private function resizeNormal($w, $h) {
    // set data
    $size = $this-&gt;info;
    $im = $this-&gt;gdID;
    $newwidth = $size[0];
    $newheight = $size[1];

    if( $newwidth &gt; $w ){
        $newheight = ($w / $newwidth) * $newheight;
        $newwidth = $w;
    }
    if( $newheight &gt; $h ){
        $newwidth = ($h / $newheight) * $newwidth;
        $newheight = $h;
    }

    $new = imagecreatetruecolor($newwidth, $newheight);
    $result = imagecopyresampled($new, $im, 0, 0, 0, 0, $newwidth, $newheight, $size[0], $size[1]);

    @imagedestroy($im);
    $this-&gt;gdID = $new;
    $this-&gt;updateInfo();

    return $result;
}

/**
 * Resize an image cutting it, do resize
 * adapt it resizing and cutting the original image
 *
 * @param integer $w
 * @param integer $h
 */
private function resizeWithCut($w, $h){
    // set data
    $size = $this-&gt;info;
    $im = $this-&gt;gdID;

    if( $size[0]&gt;$w or $size[1]&gt;$h ){
        $centerX = $size[0]/2;
        $centerY = $size[1]/2;

        $propX = $w / $size[0];
        $propY = $h / $size[1];

        if( $propX &lt; $propY ){
            $src_x = $centerX - ($w*(1/$propY)/2);
            $src_y = 0;
            $src_w = ceil($w * 1/$propY);
            $src_h = $size[1];
        }
        else {
            $src_x = 0;
            $src_y = $centerY - ($h*(1/$propX)/2);
            $src_w = $size[0];
            $src_h = ceil($h * 1/$propX);
        }

        // Resize
  $new = imagecreatetruecolor($w, $h);
        $result = imagecopyresampled($new, $im, 0, 0, $src_x, $src_y, $w, $h, $src_w, $src_h);
        
        @imagedestroy($im);
    }
    else{
        $new = $im;
    }

    $this-&gt;gdID = $new;
    $this-&gt;updateInfo();

    return $result;
}

/**
 * Add a Water Mark to the image
 * (filigrana)
 *
 * @param string $from
 * @param string $waterMark
 */
public function addWaterMarkImage($waterMark, $opacity = 35, $x = 5, $y = 5){
    // set data
    $size = $this-&gt;info;
    $im = $this-&gt;gdID;

    // set WaterMark's data    
    $waterMarkSM = new SmartImage($waterMark);
    $imWM = $waterMarkSM-&gt;getGDid();

    // Add it!
    // In png watermark images we ignore the opacity (you have to set it in the watermark image)
    if ($waterMarkSM-&gt;info[2] == 3)
        imageCopy($im, $imWM, $x, $y, 0, 0, imagesx($imWM), imagesy($imWM));
    else
        imageCopyMerge($im, $imWM, $x, $y, 0, 0, imagesx($imWM), imagesy($imWM), $opacity);
    $waterMarkSM-&gt;close();

    $this-&gt;gdID = $im;
}

/**
 * Rotate of $degrees
 *
 * @param integer $degrees
 */  
</code></pre>
<p dir="auto">public function rotate($degrees=180) {<br />
$this-&gt;gdID = imagerotate($this-&gt;gdID, $degrees, 0);<br />
$this-&gt;updateInfo();<br />
}</p>
<pre><code>/**
 * Show Image
 *
 * @param integer 0-100 $jpegQuality
 */
public function printImage($jpegQuality = 100) {
    $this-&gt;outPutImage('', $jpegQuality);
}

/**
 * Save the image on filesystem
 *
 * @param string $destination
 * @param integer 0-100 $jpegQuality
 */
public function saveImage($destination, $jpegQuality = 100) {
    $this-&gt;outPutImage($destination, $jpegQuality);
}

/**
 * Output an image
 * accessible throught printImage() and saveImage()
 *
 * @param unknown_type $dest
 * @param unknown_type $jpegQuality
 */
private function outPutImage($dest = '', $jpegQuality = 100) {
    $size = $this-&gt;info;
    $im = $this-&gt;gdID;
    // select mime
    if (!empty($dest))
        list($size['mime'], $size[2]) = $this-&gt;findMime($dest);
    
    // if output set headers
    if (empty($dest))    header('Content-Type: ' . $size['mime']);
    
    // output image
    if( $size[2] == 2 )            imagejpeg($im, $dest, $jpegQuality);
    elseif ( $size[2] == 1 )    imagegif($im, $dest);
    elseif ( $size[2] == 3 )    imagepng($im, $dest);
}

/**
 * Mime type for a file
 *
 * @param string $file
 * @return string
 */
private function findMime($file) {
    $file .= ".";
    $bit = explode(".", $file);
    $ext = $bit[count($bit)-2];
    if ($ext == 'jpg')        return array('image/jpeg', 2);
    elseif ($ext == 'jpeg')    return array('image/jpeg', 2);
    elseif ($ext == 'gif')    return array('image/gif', 1);
    elseif ($ext == 'png')    return array('image/png', 3);
    else return array('image/jpeg', 2);
}

/**
 * Get the GD identifier
 *
 * @return GD Identifier
 */
public function getGDid() {
    return $this-&gt;gdID;
}

/**
 * Get actual Image Size
 *
 * @return array('x' = integer, 'y' = integer)
 */
public function getSize() {
$size = $this-&gt;info;
    return array('x' =&gt; $size[0], 'y' =&gt; $size[1]);
}

/**
 * Set GD identifier
 *
 * @param GD Identifier $value
 */
public function setGDid($value) {
    $this-&gt;gdID = $value;
}

/**
 * Free memory
 */
public function close() {
    @imagedestroy($this-&gt;gdID);
}

/**
 * Update info class's variable
 */
private function updateInfo() {
    $info = $this-&gt;info;
    $im = $this-&gt;gdID;
    
    $info[0] = imagesx($im);
    $info[1] = imagesy($im);
    
    $this-&gt;info = $info;
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">?&gt;</p>
<p dir="auto"><strong>questo è il codice php per la miniatura priva del watermark:</strong><br />
&lt;?php</p>
<p dir="auto">/**</p>
<ul>
<li>Smart, easy and simple Image Manipulation</li>
<li></li>
<li>@author Alessandro Coscia, Milano, Italy,<br />
*codicefacile  .it/ smartimage</li>
<li>@copyright LGPL</li>
<li></li>
</ul>
<p dir="auto">*/<br />
include "SmartImage.class.php";</p>
<p dir="auto">// Settings<br />
$src = "<a href="http://www.giorgiotave.it/forum/images/car.jpg" rel="nofollow ugc">http://www.giorgiotave.it/forum/images/car.jpg</a>";<br />
$destination = "small/";</p>
<p dir="auto">// Start!<br />
$img = new SmartImage($src);<br />
// Resize and save to file<br />
$img-&gt;resize(120, 80, true);<br />
$img-&gt;saveImage($destination."new01.jpg", 76);</p>
<p dir="auto">// output image<br />
$img-&gt;printImage();</p>
<p dir="auto">$img-&gt;close();</p>
<p dir="auto">?&gt;</p>
<p dir="auto"><strong>questo è il codice php per l'immagine con dimenzione 400x300 con watermark</strong><br />
&lt;?php</p>
<p dir="auto">/**</p>
<ul>
<li>Smart, easy and simple Image Manipulation</li>
<li></li>
<li>@author Alessandro Coscia, Milano, Italy,</li>
<li>codicefacile  .it smartimage</li>
<li>@copyright LGPL</li>
<li></li>
</ul>
<p dir="auto">*/<br />
include "SmartImage.class.php";</p>
<p dir="auto">// Settings<br />
$src = "<a href="http://www.giorgiotave.it/forum/images/car.jpg" rel="nofollow ugc">http://www.giorgiotave.it/forum/images/car.jpg</a>";<br />
$waterMark = "<a href="http://www.giorgiotave.it/forum/images/smartimage.gif" rel="nofollow ugc">http://www.giorgiotave.it/forum/images/smartimage.gif</a>";<br />
$destination = "newimages/";</p>
<p dir="auto">// Start!<br />
$img = new SmartImage($src);<br />
// Resize and save to file<br />
$img-&gt;resize(400, 220, true);<br />
$img-&gt;saveImage($destination."new01.jpg");</p>
<p dir="auto">// Put a Water Mark and save to file<br />
$img-&gt;addWaterMarkImage($waterMark);<br />
$img-&gt;saveImage($destination."new01.jpg", 76);</p>
<p dir="auto">// output image<br />
$img-&gt;printImage();</p>
<p dir="auto">$img-&gt;close();</p>
<p dir="auto">?&gt;</p>
<p dir="auto">Ora volendo riscrivere un unico codice che mi permetta di avere due immagini una 120x80 e una 400x300 con watermark con cartelle di destinazione differenti come potrei fare?<br />
Sicuro di una vostra risposta vi auguro buona giornata.</p>
]]></description><link>https://dev.connect.gt/post/816199</link><guid isPermaLink="true">https://dev.connect.gt/post/816199</guid><dc:creator><![CDATA[colvi]]></dc:creator><pubDate>Sat, 14 Mar 2009 09:13:22 GMT</pubDate></item><item><title><![CDATA[Reply to Php Thumbnail e watermark on Fri, 13 Mar 2009 14:41:12 GMT]]></title><description><![CDATA[<p dir="auto">Si, è possibile utilizzando font TrueType (e mi sembra anche FreeType).<br />
Controlla tra tutte le funzioni disponibili della libreria GD e vedrai che ti permette di fare molte cose <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f609.png?v=2190ae3dadd" class="not-responsive emoji emoji-android emoji--wink" style="height:1.4em;width:auto;vertical-align:middle" title=";)" alt="😉" /></p>
<p dir="auto">Alessandro</p>
]]></description><link>https://dev.connect.gt/post/816202</link><guid isPermaLink="true">https://dev.connect.gt/post/816202</guid><dc:creator><![CDATA[magicale]]></dc:creator><pubDate>Fri, 13 Mar 2009 14:41:12 GMT</pubDate></item><item><title><![CDATA[Reply to Php Thumbnail e watermark on Fri, 13 Mar 2009 14:34:12 GMT]]></title><description><![CDATA[<p dir="auto">Grazie sei un grande, volendo sostituire l'immagine utilizzata nel watermark con del testo come posso fare? è fattibile?<br />
Grazie <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/1dfce77e-6546-41fc-8208-573e5e3f9593-figo.gif?v=2190ae3dadd" class="not-responsive emoji emoji-customizations emoji--figo2" style="height:1.4em;width:auto;vertical-align:middle" title=":figo2:" alt="" /> se capiti dalle mie parti ti offro un caffè.</p>
]]></description><link>https://dev.connect.gt/post/816198</link><guid isPermaLink="true">https://dev.connect.gt/post/816198</guid><dc:creator><![CDATA[colvi]]></dc:creator><pubDate>Fri, 13 Mar 2009 14:34:12 GMT</pubDate></item><item><title><![CDATA[Reply to Php Thumbnail e watermark on Fri, 13 Mar 2009 14:14:47 GMT]]></title><description><![CDATA[<p dir="auto">Lo puoi fare con quella stessa libreria, con la funzione</p>
<pre><code class="language-php">imagecopymerge()
</code></pre>
<p dir="auto">Un esempio/tutorial lo trovi qui:<br />
www . <a href="http://sitepoint.com/article/watermark-images-php/" rel="nofollow ugc">sitepoint.com/article/watermark-images-php/</a></p>
<p dir="auto">Alessandro</p>
]]></description><link>https://dev.connect.gt/post/816200</link><guid isPermaLink="true">https://dev.connect.gt/post/816200</guid><dc:creator><![CDATA[magicale]]></dc:creator><pubDate>Fri, 13 Mar 2009 14:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to Php Thumbnail e watermark on Fri, 13 Mar 2009 14:09:42 GMT]]></title><description><![CDATA[<p dir="auto">Grazie ma vorrei qualcosa che mi permetta di effettuare anche il watermark.<br />
Aiutatemiiiiiiiiiiiii <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/8d7b9529-9868-4606-8ca1-85ca7d28c845-wink.gif?v=2190ae3dadd" class="not-responsive emoji emoji-customizations emoji--wink3" style="height:1.4em;width:auto;vertical-align:middle" title=":wink3:" alt="" /> dai che sono certo che c'è qualcuno che l'ha già fatto.</p>
]]></description><link>https://dev.connect.gt/post/816197</link><guid isPermaLink="true">https://dev.connect.gt/post/816197</guid><dc:creator><![CDATA[colvi]]></dc:creator><pubDate>Fri, 13 Mar 2009 14:09:42 GMT</pubDate></item><item><title><![CDATA[Reply to Php Thumbnail e watermark on Fri, 13 Mar 2009 12:04:15 GMT]]></title><description><![CDATA[<p dir="auto">Ciao,<br />
se hai la GD Library installata puoi usare quella per il resize delle immagini.</p>
<p dir="auto">Qui trovi alcuni esempi:<br />
it . <a href="http://php.net/manual/en/function.imagecopyresampled.php" rel="nofollow ugc">php.net/manual/en/function.imagecopyresampled.php</a></p>
<p dir="auto">Per salvare le immagini il codice:</p>
<pre><code class="language-php">header('Content-type: image/jpeg');
</code></pre>
<p dir="auto">non serve.</p>
<p dir="auto">E devi modificare</p>
<pre><code class="language-php">imagejpeg($image_p,null,100);
</code></pre>
<p dir="auto">sostituendo a <strong>null</strong> il nome del file da salvare con il suo percorso.<br />
Ad esempio:</p>
<pre><code>"/small/immagine1.jpg"
</code></pre>
<p dir="auto">Alessandro</p>
]]></description><link>https://dev.connect.gt/post/816201</link><guid isPermaLink="true">https://dev.connect.gt/post/816201</guid><dc:creator><![CDATA[magicale]]></dc:creator><pubDate>Fri, 13 Mar 2009 12:04:15 GMT</pubDate></item></channel></rss>