Convert caption to PHP image

Background

I am upgrading a PHP application from 5.3 to 7. I am currently targeting 5.6 to start with.

There is a part of the application that converts the signature to an image. When this file runs, I get this error.

Mistake

Fatal error : Allowed memory size 33554432 bytes exhausted (tried to allocate 20480 bytes) in signature-to-image.php on line 43

This is the line that the error refers to.

code

$img = imagecreatetruecolor($options['imageSize'][0] * $options['drawMultiplier'], $options['imageSize'][1] * $options['drawMultiplier']);

      

Question

Can anyone please clarify the problem here?

I thought it had something to do with the server configuration and not a PHP issue. Any help would be greatly appreciated.

array(5) {
  ["imageSize"]=>
  array(2) {
    [0]=>
    int(373)
    [1]=>
    int(95)
  }
  ["bgColour"]=>
  array(3) {
    [0]=>
    int(255)
    [1]=>
    int(255)
    [2]=>
    int(255)
  }
  ["penWidth"]=>
  int(2)
  ["penColour"]=>
  array(3) {
    [0]=>
    int(0)
    [1]=>
    int(0)
    [2]=>
    int(0)
  }
  ["drawMultiplier"]=>
  int(12)
}
<br />
<b>Fatal error</b>:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 20480 bytes)

      

+3


source to share


1 answer


It seems that your php

script needs more memory than what is specified in the php.ini setting memory_limit

.

You have 2 options:

1 - edit php.ini parameter memory_limit

to a higher value and restart apache

.



2 - Add the following to your script:

ini_set('memory_limit', '128M') # try several values until you find the appropriate one, no more no less.

      

+2


source







All Articles