Benvenuto nella nostra community, registra un account gratuito ADESSO!
Oltre 7000 persone hanno già registrato il loro account. Chiedi aiuto, conversa con aziende ed esperti del settore webhosting italiano.
Iscriviti subito! In meno di 2 minuti!




Risultati da 1 a 6 di 6
  1. #1
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75

    Arrow [PHP] watermark e qualità immagine...

    Salve gente, stavo provando un simpatico script in php che mi permette tramite il mod rewrite di inserire un watermark nelle immagini jpg del mio sito...

    Lo script funziona veramente bene, l'unico problema è che le immagini vengono compresse troppo, e noto troppa differenza tra l'immagine originale e quella generata dallo script...

    Il codice è questo:

    Codice PHP:
    <?php
    //watermark program
    //Show that a jpeg image is going to be returned
    //echo $QUERY_STRING;
    //exit;
    header("Content-type: image/jpeg");

    //File names
    $wmark='watermark.png';
    $wmarks='watermark_s.png';
    $noimg='noimg.png';
    $mimage=$QUERY_STRING;

    // mod to display default image instead of 404
    if (file_exists($QUERY_STRING)) {
      
    //echo "The file $QUERY_STRING exists";

    //Loading
    $watermark_img imagecreatefrompng($wmark);
    $watermarks_img imagecreatefrompng($wmarks);

    $wmrk_size getimagesize($wmark);
    $wmrks_size getimagesize($wmarks);

    $main_img imagecreatefromjpeg($mimage);
    //ImageAlphaBlending($main_image, true);

    //Merge the 2 buffers
    //The figure "300" can be changed to any figure suitable for your situation.

    if (ImageSX($main_img) > 300) {
        
    $posx = (0);
        
    $posy = (ImageSY($main_img) - ImageSY($watermark_img));
    imagecopy($main_img$watermark_img$posx$posy00$wmrk_size[0], $wmrk_size[1]);
        }else{
        
    $posxs = (ImageSX($main_img) - ImageSX($watermarks_img))/2;
        
    $posys = (ImageSY($main_img) - ImageSY($watermarks_img))/2;
    imagecopy($main_img$watermarks_img$posxs$posys00$wmrks_size[0], $wmrks_size[1]);
        }

    //Output file to browser
    imagejpeg($main_img);
    imagedestroy($watermark_img);
    imagedestroy($watermarks_img);
    imagedestroy($main_img);

    } else {
    //echo "The file $QUERY_STRING does not exist";

    //Loading
    $noimg_show imagecreatefrompng($noimg);

    //Output file to browser
    imagejpeg($noimg_show);
    imagedestroy($noimg_show);

    }
    ?>
    Ho fatto varie prove, in una ho eliminato completamente l'if, così che venissero eseguiti solamente questi comandi:
    Codice PHP:
    $main_img imagecreatefromjpeg($mimage);
    //Output file to browser
    imagejpeg($main_img);
    imagedestroy($watermark_img);
    imagedestroy($watermarks_img);
    imagedestroy($main_img); 
    Ma anche così l'immagine risulta troppo compressa. Ho cercato info sulla funzione imagecreatefromjpeg ma ho scoperto che non ha alcuna opzione...
    Ho supposto a questo punto che potesse essere un'opzione delle GD lib, ma anche li google non mi è stato d'aiuto...

    Qualche suggerimento?

    Ultima modifica di JD82; 27-03-2006 alle 21:33



  2. #2
    /etc/init.d/brain restart L'avatar di Luca
    Data Registrazione
    Feb 2006
    Località
    Bellaria
    Messaggi
    3,271
    Prova con questo

    Codice PHP:
    <?php 
    function waterMark($fileInHD$wmFile$transparency 50$jpegQuality 90$margin 5) { 
     
     
    $wmImg  imageCreateFromGIF($wmFile); 
     
    $jpegImg imageCreateFromJPEG($fileInHD); 
     
     
    // Water mark in posiszione random 
     
    $wmX = (bool)rand(0,1) ? $margin : (imageSX($jpegImg) - imageSX($wmImg)) - $margin
     
    $wmY = (bool)rand(0,1) ? $margin : (imageSY($jpegImg) - imageSY($wmImg)) - $margin
     
     
    // Water mark process 
     
    imageCopyMerge($jpegImg$wmImg$wmX$wmY00imageSX($wmImg), imageSY($wmImg), $transparency); 
     
     
    // Overwriting dell'immagine 
     
    ImageJPEG($jpegImg$fileInHD$jpegQuality); 

     
    waterMark('myImage.jpg','waterMark.gif'); 
     
    ?>
    Oppure aspettiamo daniele che è lui il dottore che sa curare PHP

  3. #3
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75
    Mitticcoo! : D
    Funziona! Ho modificato il mio script aggiungendo l'opzione per la qualità:
    Codice PHP:
    imagejpeg($main_img''$jpegQuality); 
    Qualcuno però mi sa spiegare che differenza c'è tra imagejpeg e ImageJPEG? e, se c'è differenza, quando usare uno e quando l'altro?

  4. #4
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75

    404

    Mi piacerebbe fare un'ulteriore modifica allo script: vorrei che in caso si cercasse un'immagine inesistente venisse visualizzato l'errore di default di apache... solo che non ho la minima idea di come fare...



    PS
    questo è l'.htaccess della cartella immagini:
    Codice:
    RewriteEngine     on
    RewriteRule    ^(.*)\.jpg        /[full path to your image.php directory]/image.php?%{REQUEST_FILENAME}
    Ultima modifica di JD82; 27-03-2006 alle 22:22

  5. #5
    Webhosting Guru L'avatar di daniele_dll
    Data Registrazione
    Feb 2006
    Località
    Qualcuno dice Sicilia, qualche altro Nord Africa
    Messaggi
    1,535
    beh ... basta che nello script fai un bel file_exists e se il file non c'è mandi un header status 404 ^^

    ---

    per quanto riguarda lo script ci sono altre possibilità, ovvero fare il watermark usando i css, anche se ovviamente quando viene salvata la pagina, questa, verrebbe scaricata senza che le immagini col watermark

    dovresti provare a leggere la qualità della jpeg originale per poter provare a calcolare una qualità d'immagine adatta

  6. #6
    HT Member
    Data Registrazione
    Feb 2006
    Messaggi
    75
    Ciao Daniele, grazie per la risposta. Ho modificato lo script così:

    Codice PHP:
    <?php
    //watermark program
    //Show that a jpeg image is going to be returned
    //echo $QUERY_STRING;
    //exit;


    //File names
    $jpegQuality 90;
    $wmark='watermark.png';
    $wmarks='watermark_s.png';
    $noimg='noimg.png';
    $mimage=$QUERY_STRING;

    // mod to display default image instead of 404
    if (file_exists($QUERY_STRING)) {
    //  echo "The file $QUERY_STRING exists";
      
        
    header("Content-type: image/jpeg");

        
    //Loading
        
    $watermark_img imagecreatefrompng($wmark);
        
    $watermarks_img imagecreatefrompng($wmarks);
        
        
    $wmrk_size getimagesize($wmark);
        
    $wmrks_size getimagesize($wmarks);
        
        
    $main_img imagecreatefromjpeg($mimage);
        
    //ImageAlphaBlending($main_image, true);
        
        //Merge the 2 buffers
        //The figure "300" can be changed to any figure suitable for your situation.
        
        
    if ((ImageSX($main_img) > 500) && (ImageSY($main_img) > 300)) {
            
    $posx = (0);
            
    $posy = (ImageSY($main_img) - ImageSY($watermark_img));
        
    imagecopy($main_img$watermark_img$posx$posy00$wmrk_size[0], $wmrk_size[1]);
            }else{
            
    $posxs = (0);
            
    $posys = (ImageSY($main_img) - ImageSY($watermarks_img));
        
    imagecopy($main_img$watermarks_img$posxs$posys00$wmrks_size[0], $wmrks_size[1]);
            }
        
        
    //Output file to browser
        
    imagejpeg($main_img''$jpegQuality);
        
    imagedestroy($watermark_img);
        
    imagedestroy($watermarks_img);
        
    imagedestroy($main_img);

    } else {
        
    //echo "The file $QUERY_STRING does not exist";
    /*    
        //Loading
        $noimg_show = imagecreatefrompng($noimg);
        
        //Output file to browser
        imagejpeg($noimg_show, '', $jpegQuality);
        imagedestroy($noimg_show);
    */
       
    header("HTTP/1.0 404 Not Found");
       echo 
    "<HTML>
    <HEAD>
    <TITLE>404 Not Found</TITLE>
    </HEAD>
    <BODY>
    <H1>Not Found</H1>
    The requested document was not found on this server.
    <P>
    <HR>
    <ADDRESS>
    Web Server at gambacicli.com
    </ADDRESS>
    </BODY>
    </HTML>

    <!--
       - Unfortunately, Microsoft has added a clever new
       - \"feature\" to Internet Explorer. If the text of
       - an error's message is \"too small\", specifically
       - less than 512 bytes, Internet Explorer returns
       - its own error message. You can turn that off,
       - but it's pretty tricky to find switch called
       - \"smart error messages\". That means, of course,
       - that short error messages are censored by default.
       - IIS always returns error messages that are long
       - enough to make Internet Explorer happy. The
       - workaround is pretty simple: pad the error
       - message with a big comment like this to push it
       - over the five hundred and twelve bytes minimum.
       - Of course, that's exactly what you're reading
       - right now.
       -->
    "
    ; die();
        
    }
    ?>
    E pare funzionare bene (l'header che ho messo va bene?)... Volevo però sapere se c'è un modo più elegante per visualizzare la pagina di errore di default... con questa soluzione in caso modifichi la suddetta pagina devo aggiornare anche lo script...

Discussioni Simili

  1. Immagine HostingTalk.it
    Di Bowser nel forum Annunci & News
    Risposte: 4
    Ultimo Messaggio: 14-06-2010, 12:31
  2. Dimensioni Immagine per PUZZLE
    Di iettafune nel forum Off-Topic
    Risposte: 19
    Ultimo Messaggio: 17-09-2009, 16:35
  3. far corrispondere parametro con immagine
    Di floppydischetto nel forum Io Programmo
    Risposte: 5
    Ultimo Messaggio: 22-11-2008, 19:07
  4. immagine dorsali cercasi
    Di glazio nel forum Off-Topic
    Risposte: 5
    Ultimo Messaggio: 21-06-2006, 10:29
  5. [PHP] watermark e qualità immagine...
    Di JD82 nel forum Io Programmo
    Risposte: 5
    Ultimo Messaggio: 28-03-2006, 14:06

Informazioni Discussione

Utenti che Stanno Visualizzando Questa Discussione

Ci sono attualmente 1 utenti che stanno visualizzando questa discussione. (0 utenti e 1 ospiti)

Tag per Questa Discussione

Segnalibri

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  •