0

I'm new to use namespaces so I may be missing something obvious. I am trying to get the colorizzae to work but keep getting missing files messages. I have copied the example from that page and changed the path to autoload that is on my server. So my code looks like this

    require_once 'C:\Users\myuser\vendor\autoload.php';

    use Colorizzar\ChangeColor;

    $changeColor = new ChangeColor('red_car.png');

    //From Red Hexadecimal
    $changeColor->setFromHex('#FF1F28');

    // Will create 'blue.png' in new_cars/ folder
    $changeColor->colorizeByNameColor('Blue', 'new_cars/');

But when I run that I get the error

Class 'Colorizzar\ChangeColor' not found

So after the namespace statement I added

    include('c:\wamp\tests\Colorizzar\ChangeColor.php');    

That fixed that error but then another popped up for another file in the Colorizzar directory. I added that and then a third one popped up. It seems wrong that I have to include all of the files in the directory. Am I missing some general include or use statement?

user3052443
  • 758
  • 1
  • 7
  • 22
  • 1
    Did you add Colorizzar using composer? – Nigel Ren Sep 21 '19 at 16:28
  • Please reference my answer [here](https://stackoverflow.com/questions/57865692/how-to-make-sure-the-correct-class-file-is-loaded-when-calling-extending-class/57885929#57885929) about file autoloading. – Koala Yeung Sep 21 '19 at 16:56
  • Possible duplicate of [How to make sure the correct class file is loaded when calling / extending class](https://stackoverflow.com/questions/57865692/how-to-make-sure-the-correct-class-file-is-loaded-when-calling-extending-class) – Koala Yeung Sep 21 '19 at 16:57
  • @Nigel -I installed composer and it created an autoload file. I thought that was all that was needed. I've no idea how to install Colorizzar with it and can't find any instructions. I guess it is assumed one should know how to do this, – user3052443 Sep 21 '19 at 18:11
  • @Koala - I looked at your post but didn't understand it. The Colorizzar package comes with a composer.json file but I've no idea how to include it, assuming that is what is needed. – user3052443 Sep 21 '19 at 18:13
  • 1
    In the directory of your project (where the composer.json file is) run `composer install gabrieldarezzo/colorizzar` – Nigel Ren Sep 21 '19 at 18:22
  • 1
    @user3052433: You shouldn't download or clone the colorizar package directly. Instead, you initialize your project as a composer project (`composer init`), then add colorizar as a dependency (as NigelRen suggested, use the commnd `composer install gabrieldarezzo/colorizzar`). The generated autoloader will handle class file loading for you. – Koala Yeung Sep 22 '19 at 01:40
  • Thank you both. composer install... failed but it said to use composer require... and that worked. It said the autoload files were created but I don't see where they are. If I move this product to a different directory do I have to run composer again? It seems it would be much easier to just copy files and change the include path. – user3052443 Sep 22 '19 at 16:40

0 Answers0