Image upload error

Best community, I am new to this platform, i am experiencing error to upload pictures on open monograph press, i thought problem was old platform we were on version 3.3.0.13, it was update to 3.4.0.5, the problem still exists, OMP is installed on Ubuntu 22.04.4 LTS and PHP version 8.0.30, we have Dev site for testing, and it also updated to 3.4.0.5 and is running on Cent OS version 7 , PHP version 8.2.20. Platform is working flawlessly. please help me to locate this error. I have attached pic and cycle error.

There is My apache error logs

Analyse this apache logs [Wed Jun 26 12:10:47.974912 2024] [php:notice] [pid 3569] [client 196.254.83.15:50283] Slim Application Error:\nType: Error\nMessage: Call to undefined function APP\publication\imagecreatefrompng()\nFile: /var/www/html/classes/publication/Repository.php\nLine: 437\nTrace: #0 /var/www/html/classes/publication/Repository.php(282): APP\publication\Repository->makeThumbnail()\n#1 /var/www/html/lib/pkp/api/v1/submissions/PKPSubmissionHandler.php(1123): APP\publication\Repository->edit()\n#2 [internal function]: PKP\API\v1\submissions\PKPSubmissionHandler->editPublication()\n#3 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(40): call_user_func()\n#4 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/Route.php(281): Slim\Handlers\Strategies\RequestResponse->__invoke()\n#5 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\Route->__invoke()\n#6 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/Route.php(268): Slim\Route->callMiddlewareStack()\n#7 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/App.php(503): Slim\Route->run()\n#8 /var/www/html/lib/pkp/classes/security/authorization/internal/ApiAuthorizationMiddleware.php(90): Slim\App->__invoke()\n#9 [internal function]: PKP\security\authorization\internal\ApiAuthorizationMiddleware->__invoke()\n#10 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()\n#11 [internal function]: Slim\DeferredCallable->__invoke()\n#12 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()\n#13 /var/www/html/lib/pkp/classes/security/authorization/internal/ApiCsrfMiddleware.php(56): Slim\App->Slim\{closure}()\n#14 [internal function]: PKP\security\authorization\internal\ApiCsrfMiddleware->__invoke()\n#15 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()\n#16 [internal function]: Slim\DeferredCallable->__invoke()\n#17 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()\n#18 /var/www/html/lib/pkp/classes/security/authorization/internal/ApiTokenDecodingMiddleware.php(140): Slim\App->Slim\{closure}()\n#19 [internal function]: PKP\security\authorization\internal\ApiTokenDecodingMiddleware->__invoke()\n#20 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()\n#21 [internal function]: Slim\DeferredCallable->__invoke()\n#22 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()\n#23 /var/www/html/lib/pkp/classes/handler/APIHandler.php(83): Slim\App->Slim\{closure}()\n#24 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}()\n#25 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()\n#26 [internal function]: Slim\DeferredCallable->__invoke()\n#27 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()\n#28 /var/www/html/lib/pkp/classes/handler/APIHandler.php(100): Slim\App->Slim\{closure}()\n#29 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}()\n#30 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()\n#31 [internal function]: Slim\DeferredCallable->__invoke()\n#32 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()\n#33 /var/www/html/lib/pkp/classes/handler/APIHandler.php(105): Slim\App->Slim\{closure}()\n#34 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}()\n#35 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()\n#36 [internal function]: Slim\DeferredCallable->__invoke()\n#37 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()\n#38 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}()\n#39 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/App.php(392): Slim\App->callMiddlewareStack()\n#40 /var/www/html/lib/pkp/classes/handler/APIHandler.php(98): Slim\App->process()\n#41 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}()\n#42 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()\n#43 [internal function]: Slim\DeferredCallable->__invoke()\n#44 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()\n#45 /var/www/html/lib/pkp/classes/handler/APIHandler.php(105): Slim\App->Slim\{closure}()\n#46 [internal function]: PKP\handler\APIHandler->PKP\handler\{closure}()\n#47 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/DeferredCallable.php(57): call_user_func_array()\n#48 [internal function]: Slim\DeferredCallable->__invoke()\n#49 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(70): call_user_func()\n#50 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\App->Slim\{closure}()\n#51 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/App.php(392): Slim\App->callMiddlewareStack()\n#52 /var/www/html/lib/pkp/lib/vendor/slim/slim/Slim/App.php(297): Slim\App->process()\n#53 /var/www/html/lib/pkp/classes/core/APIRouter.php(110): Slim\App->run()\n#54 /var/www/html/lib/pkp/classes/core/Dispatcher.php(165): PKP\core\APIRouter->route()\n#55 /var/www/html/lib/pkp/classes/core/PKPApplication.php(388): PKP\core\Dispatcher->dispatch()\n#56 /var/www/html/index.php(21): PKP\core\PKPApplication->execute()\n#57 {main}\nView in rendered output by enabling the “displayErrorDetails” setting.\n, referer: https://monographs.ufs.ac.za/index.php/alp/workflow/index/5/5

ChatGPT

The error message from the Apache logs indicates a problem in the Slim framework application used by Open Monograph Press (OMP). Here’s a detailed analysis of the error:

Error Summary

  • Error Type: Fatal Error
  • Error Message: Call to undefined function APP\publication\imagecreatefrompng()
  • File: /var/www/html/classes/publication/Repository.php
  • Line: 437

Trace Analysis

The error occurred during the execution of a function that attempts to create a thumbnail image from a PNG file using the imagecreatefrompng() function. This function is part of the GD library in PHP, which is used for image processing.

Possible Causes

  1. GD Library Not Installed:
  • The GD library might not be installed or enabled in your PHP environment. The function imagecreatefrompng() is part of this library, and if it’s not available, PHP will throw an undefined function error.
  1. GD Library Not Loaded:
  • The GD library might be installed but not loaded. This could happen if the PHP configuration file (php.ini) does not include the correct extension directive.
  1. Code Issue:
  • There could be an issue in the code itself, but since imagecreatefrompng() is a standard PHP function, this is unlikely unless there is a typo or misconfiguration in the function call.

Steps to Fix

1. Install GD Library

Ensure that the GD library is installed. You can install it using the following commands:

sh

Copy code

sudo apt-get update
sudo apt-get install php-gd

2. Enable GD Library

Ensure that the GD extension is enabled in your php.ini file. Look for a line that includes the gd extension and make sure it is uncommented:

ini

Copy code

extension=gd

3. Restart Apache

After installing or enabling the GD library, restart Apache to apply the changes:

sh

Copy code

sudo systemctl restart apache2

4. Verify Installation

To verify that the GD library is installed and enabled, you can create a PHP file with the following content and access it via your web browser:

php

Copy code

<?php
phpinfo();
?>

Search for the GD section in the output to confirm that the library is installed and enabled.

Example Fix in Code

If the issue persists after ensuring the GD library is installed and enabled, you might want to add a check in your PHP code to see if the function exists before calling it:

php

Copy code

if (function_exists('imagecreatefrompng')) {
    $image = imagecreatefrompng($filePath);
    // Proceed with creating the thumbnail
} else {
    // Handle the error, perhaps log it or notify the user
    error_log('GD library is not available.');
}

Conclusion

The error Call to undefined function APP\publication\imagecreatefrompng() indicates that the GD library, which provides the imagecreatefrompng() function, is not available in your PHP environment. By installing and enabling the GD library, and ensuring it is correctly configured in your php.ini file, you should be able to resolve this issue. If the problem persists, adding checks in your code to handle the absence of the GD library gracefully can also help mitigate the error.

1 Like

Hi @kamohelo_thomas_Tsel,

As you’ve noted, OMP requires the GD PHP extension to be installed and enabled.

Regards,
Alec Smecher
Public Knowledge Project Team

This topic was automatically closed after 9 days. New replies are no longer allowed.