Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2009, 13:25
Avatar de lisandro Arg
lisandro Arg
 
Fecha de Ingreso: octubre-2003
Ubicación: Cordoba, Argentina
Mensajes: 945
Antigüedad: 20 años, 6 meses
Puntos: 24
Problema con memory_limit e imagecreatefromjpeg()

Hola, llevo aproximadamente un dia tratando de arreglar esto...

Como leí en varios post el problema es con la memoria que esta función reserva para la imágen Ver post

Por alguna razón puse ini_set('memory_limit','50M'); en local y funcionó pero en el remoto no pasa nada

------------------------

Para hacer unas pruebas utilize un script de los comentarios de php.net

Código PHP:
<?php

header
('Content-Type: text/plain');

ini_set('memory_limit''50M');

function 
format_size($size) {
  if (
$size 1024) {
    return 
$size ' bytes';
  }
  else {
    
$size round($size 10242);
    
$suffix 'KB';
    if (
$size >= 1024) {
      
$size round($size 10242);
      
$suffix 'MB';
    }
    return 
$size ' ' $suffix;
  }
}

$start_mem memory_get_usage();

echo <<<INTRO
The memory required to load an image using imagecreatefromjpeg() is a function
of the image's dimensions and the images's bit depth, multipled by an overhead.
It can calculated from this formula:
Num bytes = Width * Height * Bytes per pixel * Overhead fudge factor
Where Bytes per pixel = Bit depth/8, or Bits per channel * Num channels / 8.
This script calculates the Overhead fudge factor by loading images of
various sizes.
INTRO;

echo 
"\n\n";

echo 
'Limit: ' ini_get('memory_limit') . "\n";
echo 
'Usage before: ' format_size($start_mem) . "\n";

// Place the images to load in the following array:
$images = array('image1.jpg''image2.jpg''image3.jpg');
$ffs = array();

echo 
"\n";

foreach (
$images as $image) {
  
$info getimagesize($image);
  
printf('Loading image %s, size %s * %s, bpp %s... ',
         
$image$info[0], $info[1], $info['bits']);
  
$im imagecreatefromjpeg($image);
  
$mem memory_get_usage();
  echo 
'done' "\n";
  echo 
'Memory usage: ' format_size($mem) . "\n";
  echo 
'Difference: ' format_size($mem $start_mem) . "\n";
  
$ff = (($mem $start_mem) /
         (
$info[0] * $info[1] * ($info['bits'] / 8) * $info['channels']));
  
$ffs[] = $ff;
  echo 
'Difference / (Width * Height * Bytes per pixel): ' $ff "\n";
  
imagedestroy($im);
  
$start_mem memory_get_usage();
  echo 
'Destroyed. Memory usage: ' format_size($start_mem) . "\n";

  echo 
"\n";
}

echo 
'Mean fudge factor: ' . (array_sum($ffs) / count($ffs));
que en local funciona bien pero en el remoto muestra el mismo error de siempre con la segunda imagen

Cita:
The memory required to load an image using imagecreatefromjpeg() is a function
of the image's dimensions and the images's bit depth, multipled by an overhead.
It can calculated from this formula:
Num bytes = Width * Height * Bytes per pixel * Overhead fudge factor
Where Bytes per pixel = Bit depth/8, or Bits per channel * Num channels / 8.
This script calculates the Overhead fudge factor by loading images of
various sizes.

Limit: 40M
Usage before: 60.98 KB

Loading image image1.jpg, size 1280 * 1024, bpp 8... done
Memory usage: 6.34 MB
Difference: 6.28 MB
Difference / (Width * Height * Bytes per pixel): 1.6753702799479
Destroyed. Memory usage: 63.5 KB

Loading image image2.jpg, size 2171 * 3389, bpp 8... <br />
<b>Fatal error</b>: Out of memory (allocated 33292288) (tried to allocate 2171 bytes) in <b>/homepages/39/d246724706/htdocs/GUSTAVO/proyectox/memory_limit.php</b> on line <b>49</b><br />
El error que muestra lo hace la funcion imagecreatefromjpeg a pesar que se esta aumentando el memory_limit a 50M (puedo aumentarlo a 400M y el error no cambia)

Es posible que no este cambiando realmente el limite ?