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. Script per mettere un watermark ad una foto.

Script per mettere un watermark ad una foto.

Pianificato Fissato Bloccato Spostato Coding
5 Post 3 Autori 1.9k 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.
  • E
    E
    enricoeur
    scritto su ultima modifica di
    User 0
    #1
    Script per mettere un watermark ad una foto.

    Salve,

    ho il seguente problema, sto cercando uno script php che mi consenta di applicare un semplice watermark testuale a tutte le immagini posizionate in una certa directory sul mio server LINUX.

    Esiste una soluzione GRATIS ?

    A pagamento ho trovato questo: http://www.scriptsjoint.com/watermarkscript.php

    Che a quanto pare farebbe anche molto in più...

    Sapete se esiste uno script che fa sta cosa, ma che è GRATIS ?

    Grazie

    1 Risposta Ultima Risposta
    Miglior risposta 0
    0
    • massyM
      massyM
      massy
      Moderatore
      scritto su ultima modifica di
      Super User 161
      #2

      Esiste una soluzione GRATIS ?

      Sì. Ti studi le librerei gd oppure imagemagick 🙂

      1 Risposta Ultima Risposta
      Miglior risposta 0
      0
      • E
        E
        enricoeur
        scritto su ultima modifica di
        User 0
        #3

        ti ringrazio per l'aiuto, io parlavo di qualche scriopt opensource.....,

        visto che di opensource c'è di tutto...

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

          Se ti metti a cercare script già fatti perdi più tempo...

          Qui [http://www.php.net/manual/en/ref.image.php] leggi la documentazione sulla libreria GD (la più diffusa senz'altro) e le relative funzioni. Vedi che con un paio di queste al massimo hai risolto, invece di scomodare Google. Proprio come ha detto massy 😉

          CiaoCiao

          1 Risposta Ultima Risposta
          Miglior risposta 0
          0
          • E
            E
            enricoeur
            scritto su ultima modifica di
            User 0
            #5

            Allora, lo script che devo modificare è il seguente:


            function imw_gen_image_post()
            {
             global $wpdb;
             $_exif = function_exists('exif_read_data');
             
             /* POST Actions */
             if( $_REQUEST['postact'] == 'genpost'  )
             {
             
              // GO!
              $siteurl = get_settings('siteurl');
              $num_perpage = intval($_REQUEST['num_perpage']);
              $skip_resize = intval($_REQUEST['skip_resize']);
              
              $base = str_replace("\\",'/', $_REQUEST['base_url']);
              $path = str_replace("\\",'/', $_REQUEST['base_path']);
              
              if( $path == '' )
              {
               $location = $PHP_SELF . "?page={$_REQUEST['page']}&msg=1";
               header("Location: $location");
               exit();
              }
              
              $append = $_REQUEST['append'];
              $prepend = $_REQUEST['prepend'];
              $path = str_replace(ABSPATH, '', trim($path));
              $dir = ABSPATH . $path;
              
              if($base == '' ) {
               $base =  trailingslashit($siteurl) . $path;
              }
                 if ( '/' == substr($base, -1)) $base = substr($base, 0, -1);
              if ( '/' == substr($dir, -1)) $dir = substr($dir, 0, -1);
              
              if( !file_exists($dir) ) {
               $location = $PHP_SELF . "?page={$_REQUEST['page']}&msg=2";
               header("Location: $location");
               exit();
              }
              
              $width = intval($_REQUEST['i_width']);  //$width = $width ? $width : 640;
              $height = intval($_REQUEST['i_height']); //$height = $height ? $height : 480
              
              $html = '';
              
              $n = 0;
              $files = array();
              if ($handle = opendir($dir)) {
                  while (false !== ($file = readdir($handle))) {
                      if ($file != "." && $file != "..") {
                          $files[] = $file;
                }
                  }
                  closedir($handle);
              }
              sort($files, SORT_STRING);
              
              if ( ! $skip_resize && ! wp_mkdir_p( "$dir/th" ) ) {
               echo sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), "$dir/th");
               die();
              }
              
              foreach( $files as $file) 
              {
               $img = "$dir/$file";
               
               if( ! is_file($img) ) continue;
               
               if( ($is = getimagesize($img)) === false ) continue;
               if( $is[2] >= 1 && $is[2] <= 6 && $is[2] )
               
               $fn = $file;
               $bigmode = false;
               if( ! $skip_resize &&  $is[2] != 4 ) {
                $fn = 'th/' . strtolower(str_replace('.','_thumb.', $file));
                iw_resize( $img, "$dir/$fn" , $width, $height);
            
                watermark($img); <---------------------
            
                $bigmode = true;
               }
               
               $prepend1 = str_replace('%file%', $file, $prepend);
               $append1  = str_replace('%file%', $file, $append);
               $prepend1 = str_replace('%width%', $is[0], $prepend1);
               $append1  = str_replace('%width%', $is[0], $append1);
               $prepend1 = str_replace('%height%', $is[1], $prepend1);
               $append1  = str_replace('%height%', $is[1], $append1);
               $prepend1 = str_replace('%url%', "{$base}/{$file}", $prepend1);
               $append1  = str_replace('%url%', "{$base}/{$file}", $append1);
               
               if($_exif) {
                $exif_data = exif_read_data("$dir/$file", 0, true);
                if( !( $exif_data === false ) )
                {
                 $val2 = '';
                 foreach ($exif_data as $key => $section) {
                     foreach ($section as $name => $val) {
                   $k0 = strtolower($key);
                   $k1 = strtolower($name);
                         $val2 .=  strtolower($key.'.'.$name)." = $val<br />";
                   $prepend1 = str_replace('%'.$k0.'.'.$k1.'%', $val, $prepend1);
                   $append1 = str_replace('%'.$k0.'.'.$k1.'%', $val, $append1);
                     }
                 }
                 
                 $prepend1 = str_replace('%exif%', $val2, $prepend1);
                 $append1 = str_replace('%exif%', $val2, $append1);
                 
                }
               }
               
               
               if( $is[2] != 4 ) {
                $is = getimagesize("$dir/$fn");
                $params = " {$is[3]} vspace=\"4\" alt=\"{$file}\"";
                $html .= $prepend1;
                if( $bigmode ) $html .= "<a href=\"javascript:void(0)\" onclick=\"window.open(\'{$base}/{$file}\');\" >";
                $html .= "<img src=\"{$base}/{$fn}\" $params />";
                if( $bigmode ) $html .= "</a>";
                $html .= $append1;
                $n++;
               }else{
               }
               
               // $n++;
               if( $num_perpage && ($n%$num_perpage==0) ) {
                $html .= "\n<!--more-->\n";
               }
              }
              
              $_POST['comment_status'] = 'open';
              $_POST['advanced_view'] = 1;
              $_POST['post_category'] =  array();
              $_POST['post_status'] = $_REQUEST['post_type'];
              $_POST['content'] = $html;
              $_POST['post_title'] = $_POST['post_title'] ? $_POST['post_title'] : 'Image Wizard Draft';
              
              $post_ID = write_post();
              if( $post_ID ) {
               $location = "post.php?action=edit&post=$post_ID";
              }
              else
              {
               $location = $PHP_SELF . "?page={$_REQUEST['page']}";
              }
              header("Location: $location");
              exit();
              
              
             }
             /* END */
             
             
            ?>
            

            In pratica fa questo si legge tutte le immagini in una cartella, e crea per ciascuna una miniatura, salvandola in un subdirectory della cartella madre tramite la funzione seguente:


            function iw_resize($image_path, $target_path, $max_width, $max_height)
            {
             //echo "<br/>Processing $image_path --> $target_path<br/>";
             # Load image
             $img = null;
             $ext = strtolower(end(explode('.', $image_path)));
             if ($ext == 'jpg' || $ext == 'jpeg') {
              $img = @imagecreatefromjpeg($image_path);
             } else if ($ext == 'png') {
              $img = @imagecreatefrompng($image_path);
             # Only if your version of GD includes GIF support
             } else if ($ext == 'gif') {
              $img = @imagecreatefrompng($image_path);
             }
             
             # If an image was successfully loaded, test the image for size
             if ($img) {
             
              # Get image size and scale ratio
              $width = imagesx($img);
              $height = imagesy($img);
              $scale = min($max_width/$width, $max_height/$height);
             
              # If the image is larger than the max shrink it
              if ($scale < 1) {
               $new_width = floor($scale*$width);
               $new_height = floor($scale*$height);
             
               # Create a new temporary image
               $tmp_img = imagecreatetruecolor($new_width, $new_height);
             
               # Copy and resize old image into new image
               //imagecopyresized  imagecopyresampled
               imagecopyresampled($tmp_img, $img, 0, 0, 0, 0,
                    $new_width, $new_height, $width, $height);
               imagedestroy($img);
               $img = $tmp_img;
              }
             }
             
             # Create error image if necessary
             if (!$img) {
              $img = imagecreate($max_width, $max_height);
              imagecolorallocate($img,0,0,0);
              $c = imagecolorallocate($img,70,70,70);
              imageline($img,0,0,$max_width,$max_height,$c2);
              imageline($img,$max_width,0,0,$max_height,$c2);
             }
             
             # Save the image
             imagejpeg($img, $target_path);
            }
            

            Bene allora ho detto mettiamo una funzione watermark($img) che applico a ciscuna delle immagini nel loop principale, (l'ho indicata in nero nel codice - vedi primo blocco)

            La funzione, per quel poco che ne capisco di PHP l'ho scritta così:

            function watermark($image_path)
            {
             echo "<br/>Applicazione watermark $image_path<br/>";
             # Load image
             $img = null;
             $ext = strtolower(end(explode('.', $image_path)));
             if ($ext == 'jpg' || $ext == 'jpeg') {
              $img = @imagecreatefromjpeg($image_path);
             } else if ($ext == 'png') {
              $img = @imagecreatefrompng($image_path);
             # Only if your version of GD includes GIF support
             } else if ($ext == 'gif') {
              $img = @imagecreatefrompng($image_path);
             }
             
             # If an image was successfully loaded, test the image for size
             if ($img) {
             
              # Get image size and scale ratio
              //$larghezza = imagesx($img);
              //$altezza = imagesy($img);
              //$copyright = www.miosito.com;
              $tmp_img = $img;
              $textcolor = imagecolorallocate($tmp_img, 255, 255, 255);
              imagestring($tmp_img, 5, 6, 6, www.miosito.com, $textcolor);
              //$scale = min($max_width/$width, $max_height/$height);
                 imagedestroy($img);
              $img = $tmp_img;
              # If the image is larger than the max shrink it
            /*  if ($scale < 1) {
               $new_width = floor($scale*$width);
               $new_height = floor($scale*$height);
             
               # Create a new temporary image
               $tmp_img = imagecreatetruecolor($new_width, $new_height);
             
               # Copy and resize old image into new image
               //imagecopyresized  imagecopyresampled
               imagecopyresampled($tmp_img, $img, 0, 0, 0, 0,
                    $new_width, $new_height, $width, $height);
               imagedestroy($img);
               $img = $tmp_img;
              } 
            */
             }
             
             # Create error image if necessary
             if (!$img) {
              echo "<br/>Errore nell'immagine sorgente<br/>"; 
             }
             
             # Save the image
             imagejpeg($img, $image_path, 75);
            }
            

            In pratica vorrei che: il programma si scorre le immagini, per ciascuna crea la miniatura e poi piglia l'iimagine originale, vi applica l'watermark ( una semplice stringa col nome del mio sito ) e sovrascrive il file originale. Solo questo.

            L'errore che ricevo è il seguente, chiaramente l'watermark non me lo mette:

            Warning: imagejpeg(): 101 is not a valid Image resource in /home/content/a/m/a/amaporn86/html/wp-content/plugins/imagewiz.php on line 422
            
            Warning: Cannot modify header information - headers already sent by (output started at /home/content/a/m/a/amaporn86/html/wp-content/plugins/imagewiz.php:372) in /home/content/a/m/a/amaporn86/html/wp-content/plugins/imagewiz.php on line 194
            

            Resto in attesa di una dritta che mi illumini su cosa sbaglio.

            GRAZIE

            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.