Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Image Creation failing
    primarykey
    data
    text
    <p>I've made a script that creates an image using <code>imagecreatetruecolour()</code>. It then adds a letter to the image using the <code>imagettftext()</code> function. Some other changes are made and finally the white background is removed and it saved as a PNG file. The whole thing is put in a for loop so it creates 250 images.</p> <p>The problem I am facing is that sometimes (around 10-15 out of 250) it seems to fail to do anything after making the image so the output is either a white square or black square (of the correct size).</p> <p>I tried adding <code>sleep()</code> into it to see if it was trying to create them too quickly but the problem still persists. Anyone have any idea what might be causing that? The PHP memory limit is 128MB so I don't think that's the problem (and it also occurs and random places, sometimes the first image even).</p> <p>I'm pretty sure this hasn't been posted before but to be fair I didn't have a clue what to I'm searching for so I could have been looking in the wrong places.</p> <hr> <p>//edit</p> <p>I'm not allowed to add the whole script up here sadly (company policy blah blah) but I can upload bits of it. After further investigation I've narrowed it down to it not picking a letter (I output several variables to a csv and this column was blank on others that haven't worked)</p> <p>So here's the code that deals with that part:</p> <pre><code>$exp_str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRUSTUBWXYZ'; $letterArray = str_split($exp_str); $randLetter = rand(0,55); $text = $letterArray[$randLetter]; </code></pre> <p>And the part that puts all the image together:</p> <pre><code>imagettftext($im, $sizeRand, $angleRand, $posX, $posY, $black, $font, $text); $filename = 'images/'.$counter.'.png'; </code></pre> <p>Also the error log is empty.</p> <p>Thanks people. I spotted the error just after I posted the code. Not sure where I got the 55 from, but yes that is the correct sequence - or rather letter but some are stuck in random places. -</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload