Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
  1. La community italiana di SEO, marketing digitale e AI
  2. Categorie
  3. Coding e Sistemistica
  4. Coding
  5. Php Thumbnail e watermark

Php Thumbnail e watermark

Pianificato Fissato Bloccato Spostato Coding
7 Post 2 Autori 1.6k Visualizzazioni 1 Seguito
  • Da Vecchi a Nuovi
  • Da Nuovi a Vecchi
  • Più Voti
Rispondi
  • Risposta alla discussione
Effettua l'accesso per rispondere
Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
  • C
    C
    colvi
    scritto su ultima modifica di
    User Attivo 0
    #1
    Php Thumbnail e watermark

    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.

    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.

    Secondo Voi come potreei risolvere il problema? Qualcuno di Voi ha fatto qualcosa di simile?
    Grazie anticipatamente

    1 Risposta Ultima Risposta
    Miglior risposta 0
    0
    • M
      M
      magicale
      scritto su ultima modifica di
      User Attivo 0
      #2

      Ciao,
      se hai la GD Library installata puoi usare quella per il resize delle immagini.

      Qui trovi alcuni esempi:
      it . php.net/manual/en/function.imagecopyresampled.php

      Per salvare le immagini il codice:

      header('Content-type: image/jpeg');
      

      non serve.

      E devi modificare

      imagejpeg($image_p,null,100);
      

      sostituendo a null il nome del file da salvare con il suo percorso.
      Ad esempio:

      "/small/immagine1.jpg"
      

      Alessandro

      1 Risposta Ultima Risposta
      Miglior risposta 0
      0
      • C
        C
        colvi
        scritto su ultima modifica di
        User Attivo 0
        #3

        Grazie ma vorrei qualcosa che mi permetta di effettuare anche il watermark.
        Aiutatemiiiiiiiiiiiii dai che sono certo che c'è qualcuno che l'ha già fatto.

        1 Risposta Ultima Risposta
        Miglior risposta 0
        0
        • M
          M
          magicale
          scritto su ultima modifica di
          User Attivo 0
          #4

          Lo puoi fare con quella stessa libreria, con la funzione

          imagecopymerge()
          

          Un esempio/tutorial lo trovi qui:
          www . sitepoint.com/article/watermark-images-php/

          Alessandro

          1 Risposta Ultima Risposta
          Miglior risposta 0
          0
          • C
            C
            colvi
            scritto su ultima modifica di
            User Attivo 0
            #5

            Grazie sei un grande, volendo sostituire l'immagine utilizzata nel watermark con del testo come posso fare? è fattibile?
            Grazie se capiti dalle mie parti ti offro un caffè.

            1 Risposta Ultima Risposta
            Miglior risposta 0
            0
            • M
              M
              magicale
              scritto su ultima modifica di
              User Attivo 0
              #6

              Si, è possibile utilizzando font TrueType (e mi sembra anche FreeType).
              Controlla tra tutte le funzioni disponibili della libreria GD e vedrai che ti permette di fare molte cose 😉

              Alessandro

              1 Risposta Ultima Risposta
              Miglior risposta 0
              0
              • C
                C
                colvi
                scritto su ultima modifica di
                User Attivo 0
                #7

                To utilizzando uno script trovato in rete e devo dire che funziona
                questa è la classe:
                <?php

                /**

                • Smart, easy and simple Image Manipulation
                • @author Alessandro Coscia, Milano, Italy,
                • codicefacile. it/ smartimage
                • @copyright LGPL
                • @version 0.9.6

                /
                class SmartImage {
                /
                *
                * Source file (path)
                */
                private $src;

                /**
                 * GD image's identifier
                 */
                private $gdID;
                
                /**
                 * Image info
                 */
                private $info;
                
                /**
                 * Initialize image
                 *
                 * @param string $src
                
                • @param boolean $big
                  • @return SmartImage
                    */
                    public function SmartImage($src, $bigImageSize=false) {
                    // In case of very big images (more than 1Mb)
                    if ($bigImageSize)
                    $this->setMemoryForBigImage($src);
                // set data
                $this->src = $src;
                $this->info = getimagesize($src);
                
                // open file
                if ( $this->info[2] == 2 )        $this->gdID = imagecreatefromjpeg($this->src);
                elseif ( $this->info[2] == 1 )    $this->gdID = imagecreatefromgif($this->src);
                elseif ( $this->info[2] == 3 )     $this->gdID = imagecreatefrompng($this->src);
                
                }
                

                /**

                • Set memory in case of very big images (more than 1Mb)

                • new SmartImage($src, true) to activate this function

                • Works with (PHP 4 >= 4.3.2, PHP 5) if compiled with --enable-memory-limit

                • or PHP>=5.2.1

                • Thanks to Andrvm and to Bascunan for this feature
                  */
                  private function setMemoryForBigImage($filename) {
                  $imageInfo = getimagesize($filename);
                  $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);

                  $memoryLimit = (int) ini_get('memory_limit')*1048576;

                  if ((memory_get_usage() + $memoryNeeded) > $memoryLimit) {
                  ini_set('memory_limit', ceil((memory_get_usage() + $memoryNeeded + $memoryLimit)/1048576).'M');
                  return (true);
                  }
                  else return(false);
                  }

                /**
                 * 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->resizeWithCut($width, $height);
                    else
                    return $this->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->info;
                    $im = $this->gdID;
                    $newwidth = $size[0];
                    $newheight = $size[1];
                
                    if( $newwidth > $w ){
                        $newheight = ($w / $newwidth) * $newheight;
                        $newwidth = $w;
                    }
                    if( $newheight > $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->gdID = $new;
                    $this->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->info;
                    $im = $this->gdID;
                
                    if( $size[0]>$w or $size[1]>$h ){
                        $centerX = $size[0]/2;
                        $centerY = $size[1]/2;
                
                        $propX = $w / $size[0];
                        $propY = $h / $size[1];
                
                        if( $propX < $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->gdID = $new;
                    $this->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->info;
                    $im = $this->gdID;
                
                    // set WaterMark's data    
                    $waterMarkSM = new SmartImage($waterMark);
                    $imWM = $waterMarkSM->getGDid();
                
                    // Add it!
                    // In png watermark images we ignore the opacity (you have to set it in the watermark image)
                    if ($waterMarkSM->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->close();
                
                    $this->gdID = $im;
                }
                
                /**
                 * Rotate of $degrees
                 *
                 * @param integer $degrees
                 */  
                

                public function rotate($degrees=180) {
                $this->gdID = imagerotate($this->gdID, $degrees, 0);
                $this->updateInfo();
                }

                /**
                 * Show Image
                 *
                 * @param integer 0-100 $jpegQuality
                 */
                public function printImage($jpegQuality = 100) {
                    $this->outPutImage('', $jpegQuality);
                }
                
                /**
                 * Save the image on filesystem
                 *
                 * @param string $destination
                 * @param integer 0-100 $jpegQuality
                 */
                public function saveImage($destination, $jpegQuality = 100) {
                    $this->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->info;
                    $im = $this->gdID;
                    // select mime
                    if (!empty($dest))
                        list($size['mime'], $size[2]) = $this->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->gdID;
                }
                
                /**
                 * Get actual Image Size
                 *
                 * @return array('x' = integer, 'y' = integer)
                 */
                public function getSize() {
                $size = $this->info;
                    return array('x' => $size[0], 'y' => $size[1]);
                }
                
                /**
                 * Set GD identifier
                 *
                 * @param GD Identifier $value
                 */
                public function setGDid($value) {
                    $this->gdID = $value;
                }
                
                /**
                 * Free memory
                 */
                public function close() {
                    @imagedestroy($this->gdID);
                }
                
                /**
                 * Update info class's variable
                 */
                private function updateInfo() {
                    $info = $this->info;
                    $im = $this->gdID;
                    
                    $info[0] = imagesx($im);
                    $info[1] = imagesy($im);
                    
                    $this->info = $info;
                }
                

                }

                ?>

                questo è il codice php per la miniatura priva del watermark:
                <?php

                /**

                • Smart, easy and simple Image Manipulation
                • @author Alessandro Coscia, Milano, Italy,
                  *codicefacile .it/ smartimage
                • @copyright LGPL

                */
                include "SmartImage.class.php";

                // Settings
                $src = "http://www.giorgiotave.it/forum/images/car.jpg";
                $destination = "small/";

                // Start!
                $img = new SmartImage($src);
                // Resize and save to file
                $img->resize(120, 80, true);
                $img->saveImage($destination."new01.jpg", 76);

                // output image
                $img->printImage();

                $img->close();

                ?>

                questo è il codice php per l'immagine con dimenzione 400x300 con watermark
                <?php

                /**

                • Smart, easy and simple Image Manipulation
                • @author Alessandro Coscia, Milano, Italy,
                • codicefacile .it smartimage
                • @copyright LGPL

                */
                include "SmartImage.class.php";

                // Settings
                $src = "http://www.giorgiotave.it/forum/images/car.jpg";
                $waterMark = "http://www.giorgiotave.it/forum/images/smartimage.gif";
                $destination = "newimages/";

                // Start!
                $img = new SmartImage($src);
                // Resize and save to file
                $img->resize(400, 220, true);
                $img->saveImage($destination."new01.jpg");

                // Put a Water Mark and save to file
                $img->addWaterMarkImage($waterMark);
                $img->saveImage($destination."new01.jpg", 76);

                // output image
                $img->printImage();

                $img->close();

                ?>

                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?
                Sicuro di una vostra risposta vi auguro buona giornata.

                1 Risposta Ultima Risposta
                Miglior risposta 0
                0

                Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.

                Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.

                Con il tuo contributo, questo post potrebbe essere ancora migliore 💗

                Registrati Accedi
                Rispondi
                • Risposta alla discussione
                Effettua l'accesso per rispondere
                • Da Vecchi a Nuovi
                • Da Nuovi a Vecchi
                • Più Voti


                • Accedi

                • Non hai un account? Registrati

                • Accedi o registrati per effettuare la ricerca.
                • Primo post
                  Ultimo post
                Home Accedi Registrati
                Menu
                • CATEGORIES
                • La Community Connect.gt
                • Presentati alla Community
                • News Ufficiali da Connect.gt
                • Internet News
                • A Scuola Di
                • Digital Marketing
                • Intelligenza Artificiale
                • SEO & GEO
                • Web Marketing e Content
                • Google Analytics e Web Analytics
                • Google Ads & Advertising
                • YouTube
                • TikTok, Instagram e altri Social
                • Google Adsense, Affiliazioni e Guadagno
                • E-Commerce
                • Coding e Sistemistica
                • Help Center: consigli per il tuo progetto
                • Hosting e Cloud
                • Coding
                • CMS & Piattaforme Self-Hosted
                • Annunci e Collaborazioni
                • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
                • Collaborazioni WEB e Lavoro: offro e cerco
                • Impresa, Fisco e Leggi
                • Consulenza Legale e Professioni Web
                • Consulenza Fiscale, Imprese, Startup e P.Iva
                • Gli Off Topic
                • PC, Smartphone e altri Hardware
                • Tutti i Software
                • GT Fetish Cafè
                • Discussioni
                • Non letti 0
                • Recenti
                • Hashtag
                • Popolare
                • Utenti
                • Privacy
                • Termini e condizioni
                • © 2026 Search On Media Group S.r.l.