Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [GD2] Assurdi problemi con immagini grandi

    Ciao ragà,
    ho un problema assurdo da risolvere nel tempo più breve possibile.. Stò usando questa classe per il resize delle immagini su un sito:

    Codice PHP:
    <?

    /*

    * class.Thumbnail.php

    *

    * Copyright (C) 2001 Hidayet Dogan (hdogan@bilcag.net)

    *

    * This program is free software; you can redistribute it and/or modify

    * it under the terms of the GNU General Public License as published by

    * the Free Software Foundation; either version 2, or (at your option)

    * any later version.

    *

    * This program is distributed in the hope that it will be useful,

    * but WITHOUT ANY WARRANTY; without even the implied warranty of

    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

    * GNU General Public License for more details.

    *

    * You should have received a copy of the GNU General Public License

    * along with this program; if not, write to the Free Software

    * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    *

    */



    class Thumbnail {

        var 
    $errmsg        "";

        var 
    $error        false;

        var 
    $format        "";

        var 
    $file        "";

        var 
    $max_width  0;

        var 
    $max_height 0;

        var 
    $percent    0;

        var 
    $percent    0;

        var 
    $gd;



        

            







        function 
    Thumbnail($file$max_width 0$max_height 0$percent 0) {

        

        if (!
    file_exists($file)) {

            
    $file "uploads/default.jpg";

    //        $this->errmsg = "File doesn't exist";

    //        $this->error  = true;

        
    }

        else if (!
    is_readable($file)) {

            
    $this->errmsg "File is not readable";

            
    $this->error  true;

        }



        if (
    strstr(strtolower($file), ".gif"))

            
    $this->format "GIF";

        else if (
    strstr(strtolower($file), ".jpg") ||

             
    strstr(strtolower($file), ".jpeg"))

            
    $this->format "JPEG";

        else if (
    strstr(strtolower($file), ".png"))

            
    $this->format "PNG";

        else {

            
    $this->errmsg "Unknown file format";

            
    $this->error  true;

        }



        if (
    $max_width == && $max_height == && $percent == 0)

            
    $percent 100;



        
    $this->max_width  $max_width;

        
    $this->max_height $max_height;

        
    $this->percent      $percent;

        
    $this->file      $file;

        }



        

       function 
    gdVersion() {

           if (! 
    extension_loaded('gd')) { return; }

           
    ob_start();

           
    phpinfo(8);

           
    $info=ob_get_contents();

           
    ob_end_clean();

           
    $info=stristr($info'gd version');    

           
    preg_match('/\d/'$info$gd);

           
    $this->$gd=$gd[0];

           return 
    $this->$gd;

             }







        function 
    calc_width($width$height) {

        
    $new_width  $this->max_width;

        
    $new_wp     = (100 $new_width) / $width;

        
    $new_height = ($height $new_wp) / 100;

        return array(
    $new_width$new_height);

        }



        function 
    calc_height($width$height) {

        
    $new_height $this->max_height;

        
    $new_hp     = (100 $new_height) / $height;

        
    $new_width  = ($width $new_hp) / 100;

        return array(
    $new_width$new_height);

        }



        function 
    calc_percent($width$height) {

        
    $new_width  = ($width $this->percent) / 100;

        
    $new_height = ($height $this->percent) / 100;

        return array(
    $new_width$new_height);

        }



        function 
    return_value($array) {

        
    $array[0] = intval($array[0]);

        
    $array[1] = intval($array[1]);

        return 
    $array;

        }



        function 
    calc_image_size($width$height) {

        
    $new_size = array($width$height);



        if (
    $this->max_width 0) {

            
    $new_size $this->calc_width($width$height);



            if (
    $this->max_height 0) {

            if (
    $new_size[1] > $this->max_height)

                
    $new_size $this->calc_height($new_size[0], $new_size[1]);

            }



            return 
    $this->return_value($new_size);

        }



        if (
    $this->max_height 0) {

            
    $new_size $this->calc_height($width$height);

            return 
    $this->return_value($new_size);

        }



        if (
    $this->percent 0) {

            
    $new_size $this->calc_percent($width$height);

            return 
    $this->return_value($new_size);

        }

        }



        function 
    show_error_image() {

        
    header("Content-type: image/png");

                

        
    $err_img   ImageCreatefromgd2(22025);

        
    $bg_color  ImageColorAllocate($err_img000);

        
    $fg_color1 ImageColorAllocate($err_img255255255);

        
    $fg_color2 ImageColorAllocate($err_img25500);

        
    ImageString($err_img366"ERROR:"$fg_color2);

        
    ImageString($err_img3556$this->errmsg$fg_color1);

        
    ImagePng($err_img);

        
    ImageDestroy($err_img);

        }



        function 
    show() {

        if (
    $this->error) {

            
    $this->show_error_image();

            return;

        }



        
    $size      GetImageSize($this->file);

        
    $new_size  $this->calc_image_size($size[0], $size[1]);

        
    $new_image = ($this->gdVersion()==2) ? ImageCreatefromgd2($new_size[0], $new_size[1]) : ImageCreate($new_size[0], $new_size[1]);



        switch (
    $this->format) {

            case 
    "GIF":

            
    $old_image ImageCreateFromGif($this->file);

            break;

            case 
    "JPEG":

            
    $old_image ImageCreateFromJpeg($this->file);

            break;

            case 
    "PNG":

            
    $old_image ImageCreateFromPng($this->file);

            break;

        }



        
    ImageCopyResized($new_image$old_image0000$new_size[0], $new_size[1], $size[0], $size[1]);



        switch (
    $this->format) {

            case 
    "GIF":

            
    header("Content-type: image/gif");

            
    ImageGif($new_image);

            break;

            case 
    "JPEG":

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

            
    ImageJpeg($new_image);

            break;

            case 
    "PNG":

            
    header("Content-type: image/png");

            
    ImagePng($new_image);

            break;

        }



        
    ImageDestroy($new_image);

        
    ImageDestroy($old_image);

        return;

        }

    }

    ?>
    Potete anche non leggerla tutta in fondo sono 4 funzioni essenziali..

    Il problema è che il resize non viene effettuato con immagini superiori a circa 200K e non mi sò spiegare il perchè..

    In rete non ho trovato niente di utile.. tutto regolare eppure il problema c'è!
    Se qualcuno ne sà qualcosa mi faccia sapere

    ByeZ,
    Satoshy

  2. #2
    Utente di HTML.it L'avatar di kuarl
    Registrato dal
    Oct 2001
    Messaggi
    1,093
    che errore ti da?

  3. #3

    E' incredile..

    E' incredibile... ora stò debuggando piano piano la cosa e sono arrivato a questo punto assurdo:

    <?php
    error_reporting (E_ALL);
    $file = "immagine2.jpg";
    $new_image = ImageCreate(100, 120);

    $old_image = ImageCreateFromJpeg($file);

    ImageCopyResized($new_image, $old_image, 0, 0, 0, 0, 100, 120, 2082, 285);
    header("Content-type: image/jpeg");

    ImageJpeg($new_image);
    ?>

    L'immagine in $file non viene stampata in output se è di grandi dimensioni (tipo 200k).
    Utilizzo le GD 2.0.22 -- HELP!

    Provare per credere..

    Satoshy

  4. #4
    Credo di aver capito.. a quanto pare sembra che la cosa non dipende dal peso dell'immagine ma dalle dimensioni.

    Ma che cazz con le vecchie versioni funzionava e con la nuova no.. quessi della boutell stanno di fuori.

    Satoshy

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.