Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 514969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:34:47+00:00 2026-05-13T07:34:47+00:00

As per an assignment given to me, I am trying to see the effects

  • 0

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

I upload the file using a html and then my php code looks like this:

 <?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();
}

    ?>

But when i do this, i get the following output:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 10368 bytes) in C:\Users\zee\Documents\Flex Builder 3\CLOUD\bin-debug\upload_file.php on line 3

The size of original image is : 5,136 KB give the above error after running the php.

But if i try for other image with size : 2,752 KB It Works ..

Can someone please help me with this.
Zeeshan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:34:47+00:00Added an answer on May 13, 2026 at 7:34 am

    First of all drop the header("Content-type:image/jpeg"); line, it’s doing nothing there since you’re using the filename argument of the imagejpeg() function.

    Secondly, to avoid memory problems you should change the memory limit, something like:

    ini_set('memory_limit', -1);
    

    Should solve your problems (place it at the beginning of the file).

    To restore the original memory limit you can add the following line at the end of the file:

    ini_restore('memory_limit');
    

    The whole script should look something like this:

    <?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');
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.