[solved] Call to undefined function Bulletproof\Utils\resize()

Hi, Im using slim3, using composer to load samayo/bulletproof image app. My problem is with the utils file that is only a function. I can access and use “use Bulletproof\Image”; inside slim but not the stand alone image resize function.

error im getting…Call to undefined function Bulletproof\Utils\resize()

// file inside vendor 
namespace Bulletproof\Utils;
// no clase name only function
function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = false, $upsize = true) {//..}

im using a image controler with this function.

use Bulletproof\Image;

public function bulletproof1(Request $request, Response $response, Image $image) {


       \Bulletproof\Utils\resize(
                        $image->getFullPath(),
                        $image->getMime(),
                        $image->getWidth(),
                        $image->getHeight(),
                        50,
                        50);


You can try use function My\Full\functionName;

https://www.php.net/manual/en/language.namespaces.importing.php#example-262

thanks Odan will try

Hi, Odan still having the issue.

Using php 7.3 with Slim3, League Container.

// location for the php file
// vendor  samayo  bulletproof  src  utils  func.image-resize.php
namespace Bulletproof\Utils;
function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = false, $upsize = true)

controller file…

use function Bulletproof\Utils\resize;
use Bulletproof\Image;

public function bulletproof1(Request $request, Response $response, Image $image) {

 \Bulletproof\Utils\resize( //,,,); // tried it with this 
resize(//...); and also 
}

the error Call to undefined function Bulletproof\Utils\resize()

Ah yes, composer autoloading will not work for functions. Readme

This libary has a old-school autoloader:

 "autoload":{
        "classmap": [
            "src/"
        ]
    },

You could add the files into your composer.json autoload section instead:

  "autoload": {
        //...
        "files": [
            "vendor/samayo/bulletproof/src/utils/func.image-crop.php",
            "vendor/samayo/bulletproof/src/utils/func.image-resize.php",
            "vendor/samayo/bulletproof/src/utils/func.image-watermark.php"
        ]

Then in PHP:

use function Bulletproof\Utils\resize;

//...

resize();

Thank you, it worked…