Visualizzazione dei risultati da 1 a 4 su 4

Discussione: gd2 image processing

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    590

    gd2 image processing

    salve, lo script di seguito crea un'anteprima (thumb) dell'immagine basandosi su dei valori maxheight e maxwidth.
    esempio:150x150px
    lo script ridimensiona a 150px mantenendo l'aspect ratio (così una dimensione è 150px e l'altra è minore)
    penso di aver individuato la funzione che crea effettivamente l'immagine

    codice:
        function resizeImageGD2($src_file, $dest_file, $destWidth,$destHeight){        $imginfo = getimagesize($src_file);
            if ($imginfo == null) {
                $this->raiseError(CBTxt::T('Error: Unable to execute getimagesize function'));
                return false;
            }
            // GD can only handle JPG & PNG images
            if ($imginfo[2] != 2 && $imginfo[2] != 3 && ($imginfo[2] == 1 && !function_exists( 'imagecreatefromgif' ))){
                $this->raiseError(CBTxt::T('Error: GD2 Unable to create image from imagetype function'));
                return false;
            }
            if ($imginfo[2] == 2)
                $src_img = imagecreatefromjpeg($src_file);
            elseif ($imginfo[2] == 1)
                $src_img = imagecreatefromgif($src_file);
            else
                $src_img = imagecreatefrompng($src_file);
            if (!$src_img) {
                $this->raiseError(CBTxt::T('Error: GD2 Unable to create image from imagetype function'));
                return false;
            }
            $dst_img = imagecreatetruecolor($destWidth, $destHeight);
            $background_color    =    imagecolorallocate( $dst_img, 255, 255, 255 );        // white background for images with transparency
            ImageFilledRectangle($dst_img, 0, 0, $destWidth, $destHeight, $background_color);
            imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, $destHeight, $imginfo[0], $imginfo[1]);
            if ($imginfo[2] == 2) {
                imagejpeg($dst_img, $dest_file, $this->_JPEGquality);
            } elseif ($imginfo[2] == 1) {
                if(function_exists('imagegif')) {
                    imagegif($dst_img, $dest_file);
                } else {
                    $this->raiseError(CBTxt::T('Error: GIF Uploads are not supported by this version of GD'));
                    return false;
                }
            } else {
                imagepng($dst_img, $dest_file);
            }
            imagedestroy($src_img);
            imagedestroy($dst_img);
            return true;
        }

    questo è lo script completo
    http://forge.joomlapolis.com/attachm...lbox.class.php
    appartiene a Community Builder, un componente di joomla.

    quello che vorrei è:
    avere una thumb che abbia dimensioni fisse 150x150 (non variabili 150xX o Xx150) croppando l'immagine.
    in altre parole, per capirci, come gli avatar di facebook.
    so che è una richiesta impegnativa, ma non così tanto per chi sviluppa ed ha a che fare spesso con l'image processing.

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    590
    le funzioni in questione nello script sono resizeImage() e resizeImageGD2()


    https://gist.github.com/jasdeepkhalsa/4339969

    questo è lo script che fa quello che voglio

    ci ho provato per ore..
    Ultima modifica di jimbo0; 27-11-2013 a 01:56

  3. #3
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  4. #4
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    590
    è lo script che ho linkato nel secondo post. ho provato ad adattare questo script nel sito ma non funziona correttamente.
    la cosa strana è la riga 18 (e 24)
    $new_width=$width/($height/$thumb_height);
    ne esce un numero piccolissimo 0,00xxx
    e quel numero è usato come dimensione X dell'immagine generata

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.