Jump to content
php.lv forumi

imagecreatefromjpeg(), memory error


darklow

Recommended Posts

Man ir sekojosha atteelu samazinaashanas f-ja:

<?
function createThumb($img,$tnpath,$MAX_W,$MAX_H) {

$check=getimagesize($img);

if($check[0]>$MAX_W || $check[1]>$MAX_H){
 $orig_image = imagecreatefromjpeg($img);
 $orig_x = imagesx($orig_image);
 $orig_y = imagesy($orig_image);

 if (($orig_x / $orig_y) >= (4 / 3)) {
  $y = round($orig_y / ($orig_x / $MAX_W));
  $x = $MAX_W;
 } else {
  $x = round($orig_x / ($orig_y / $MAX_H));
  $y = $MAX_H;
 } 

 $sm_image = imagecreatetruecolor($x, $y);
 Imagecopyresampled($sm_image, $orig_image, 0, 0, 0, 0, $x, $y, $orig_x, $orig_y);
 imageJPEG($sm_image, $tnpath, 80);
 imagedestroy ($sm_image);
 imagedestroy ($orig_image);
}
}
?>

 

viss straadaa, un izdodas, tachu regulaari kaadam izmetaas errors un php nocrasho (alja die()):

1) PHP Fatal error: Allowed memory size of 15728640 bytes exhausted (tried to allocate 6000 bytes)

vai

2) PHP Fatal error: Allowed memory size of 15728640 bytes exhausted (tried to allocate 1500 bytes)

 

errors izmetaas tieshi pie shiis rindinjas

$orig_image = imagecreatefromjpeg($img);

 

sho f-ju es izsaucu ciklaa pie attelu uploada, saakotneeji lai samazinaatu attelu peec garaakaas malas, lai buutu 600px, un pec tam tajaa pashaa ciklaa velreiz veidoju thumbnail attelam.

 

lasiju, peetiju, domaaju bet beigaas taa arii nesapratu kur varetu buut probleema...

Link to comment
Share on other sites

×
×
  • Create New...