Imagecreatefromjpeg ve imagejpeg kullanarak sorunu

4 Cevap

As per an assignment given to me, I am trying to see the effects of the following two function of php on a image file 1. imagecreatefromjpeg 2. imagejpeg

Ben bir html kullanarak dosya upload ve sonra benim php kod şöyle görünür:

 <?php

 try{
   if(!$image=imagecreatefromjpeg('zee1.jpg')){
      throw new Exception('Error loading image');
   }
   // create text color for jpg image
   if(!$textColor=imagecolorallocate($image,0,255,0)){
      throw new Exception('Error creating text color');
   }
   // include text string into jpg image
   if(!$text=imagestring($image,5,10,90,'This is a sample text
string.',$textColor)){
      throw new Exception('Error creating image text');
   }
   header("Content-type:image/jpeg");
   // display image
   imagejpeg($image, 'zee1After.jpg');
   // free up memory
   imagedestroy($image);
}
catch(Exception $e){
   echo $e->getMessage();
   exit();
}

    ?>

Ben bunu Ama, ben aşağıdaki çıktıyı alıyorum:

Ölümcül hata: tükenmiş 33554432 bayt İzin bellek boyutu C (10.368 bayt ayırmaya çalıştı): \ Users \ zee \ Documents on line 3 Flex Builder 3 \ BULUTU \ bin-debug \ \ upload_file.php

Orijinal görüntünün boyutu: 5136 KB php çalıştırdıktan sonra yukarıdaki hata verir.

Ama boyutu ile diğer görüntü için çalışırsanız: Çalışır 2,752 KB ..

Can someone please help me with this. Zeeshan

4 Cevap

Öncelikle size imagejpeg() fonksiyonunun dosya argümanını kullanarak konum beri orada hiçbir şey yapıyor header("Content-type:image/jpeg"); satır, bırakın.

: İkincisi, bellek sorunları önlemek için hafıza sınırı, gibi bir şey değiştirmek gerekir

ini_set('memory_limit', -1);

(Dosyanın başında yerleştirin) sorunları çözmek gerekir.

Orijinal bellek limitini geri yüklemek için, dosyanın sonuna aşağıdaki satırı ekleyebilirsiniz:

ini_restore('memory_limit');

Bütün script bu gibi görünmelidir:

<?php

ini_set('memory_limit', -1);

try 
{
    if (!$image = imagecreatefromjpeg('zee1.jpg'))
    {
    	throw new Exception('Error loading image');
    }

    // create text color for jpg image
    if (!$textColor = imagecolorallocate($image, 0, 255, 0))
    {
    	throw new Exception('Error creating text color');
    }

    // include text string into jpg image
    if (!$text = imagestring($image, 5, 10, 90, 'This is a sample text string.', $textColor))
    {
    	throw new Exception('Error creating image text');
    }

    // display image
    imagejpeg($image, 'zee1After.jpg');

    // free up memory
    imagedestroy($image);
}

catch (Exception $e)
{
    echo $e->getMessage();
    exit();
}

ini_restore('memory_limit');

?>

Sen dosyasına dosyanın adını değil, yol talep ediyoruz. Deneyin:

$imgname = $_FILES["file"]["tmp_name"];

Warning: Cannot modify header information - headers already sent by

Açılış PHP etiketinin önce herhangi bir karakter değildir emin olun; o hata mesajı alma nedenidir. Eğer herhangi bir karakteri görmüyorsanız, bu dosya, dosya UTF-8, UTF-16 LE veya UTF kodlanmış ise bir UTF dosyasında anlamak sağlayan bir karakter dizisidir BOM dizisi ile başlar olabilir BE -16.

Eğer yankı yoluyla metni çıkış vardır çünkü öyle. Onlar zaten metin göndermek için gönderildi çünkü Başlıkları, yeniden gönderilir olamaz. Çıkış tamponlama düşünün.

See my response to a similar question.

EDIT: Ayrıca, $_FILES dizide 'tmp_name' dizini kullanarak yaklaşık Steve'in yazı bakın.