1

I used imagecreatefrompng function to generate captcha. It works fine in localhost and not in web server this is my code

$captcha_base_img = base_url("assets/images/captcha_back.png");
            $image = imagecreatefrompng($captcha_base_img); 
//returns an image identifier representing a black image of the specified size(w,h)

php info

gd GD Support enabled GD Version bundled (2.1.0 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.3.11 GIF Read Support enabled GIF Create Support enabled JPEG Support enabled libJPEG Version 6b PNG Support enabled libPNG Version 1.2.49 WBMP Support enabled XBM Support enabled

what would be the reason?

$image returns false; 

it is a png image

error log :

Warning --> imagecreatefrompng(http://url/captcha_back.png) [function.imagecreatefrompng]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

Sampath Wijesinghe
  • 789
  • 1
  • 11
  • 33
samm
  • 33
  • 1
  • 1
  • 7
  • is it the exact same image you tested with in localhost? Is it definitely there on the server in the correct location? And are you not getting an exception or warning as well as the "false" return value? – ADyson Feb 13 '18 at 13:00
  • 1
    what does your [**PHP error log**](https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php5-apache-fastcgi-cpanel) tell you? – Martin Feb 13 '18 at 13:02
  • @Martin error log Warning --> imagecreatefrompng(http://landreclamation.lk/demo_apps/assets/images/captcha_back.png) [function.imagecreatefrompng]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found – samm Feb 13 '18 at 13:20
  • 2
    So that clearly shows you the issue: your image is not there or you have access issues in reaching the image – Martin Feb 13 '18 at 13:21
  • See also : https://stackoverflow.com/questions/7454695/imagecreatefrompng-failed-to-open-stream-http-request-failed – Martin Feb 13 '18 at 13:22
  • 1
    Samm; if your image is on your local server then you **don't** need to do a remote call, but instead should be doing a `$_SERVER['DOCUMENT_ROOT']` call to the file location. – Martin Feb 13 '18 at 13:28
  • In my case, I got warnings messages in other lines which affects the functionality of the creating image. – Ricard Espinàs Llovet May 06 '20 at 07:26

0 Answers0