douquanhui5735 2019-01-13 20:40
浏览 60
已采纳

可以在没有autoload.php(作曲家)的情况下使用thephpleague / color-extractor吗?

I'my trying to use color-extractor to get the colours of my images but I'm having trouble getting it working.

I noticed a missing autoload.php file in the package and after some googling it seems it requires that you use Composer. I haven't used composer and don't have much experience using the command line yet. Something I am working on but hoping not to have to learn it all before using this php package.

I tried changing some of the php lines from this:

require 'vendor/autoload.php';

use League\ColorExtractor\Color;
use League\ColorExtractor\ColorExtractor;
use League\ColorExtractor\Palette;

to this:

require ..\lib\League\ColorExtractor\Color;
require ..\lib\League\ColorExtractor\ColorExtractor;
require ..\lib\League\ColorExtractor\Palette;

But it didn't work and I got these errors:

[14-Jan-2019 07:00:43 Australia/Sydney] PHP Fatal error:  require(): Failed opening required 'lib/League/ColorExtractor/Color.php' (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/windowvi/public_html/arena/examples/grid2/php/get_collection.php on line 3
[14-Jan-2019 07:07:14 Australia/Sydney] PHP Fatal error:  Class 'Palette' not found in /home/windowvi/public_html/arena/examples/grid2/php/get_collection.php on line 55

Can this package be used without learning and using composer and if so, how would I require/include the files?

Thanks!

  • 写回答

1条回答 默认 最新

  • drqj8605 2019-01-13 22:35
    关注

    Hopefully this will help you on your way.

    Create a project folder called e.g. ‘colorextractor’

    Copy-paste the 3 files from thephpleague/color-extractor/src/League/ColorExtractor

    1. Color.php
    2. ColorExtractor.php
    3. Palette.php

    Into your project folder.

    Then create an index.php file (see below) that will run the examples from the README at thephpleague/color-extractor – to ensure it all works as expected.

    Your project folder should have the following content: enter image description here

    Note: I used a ‘testimage.png’ to test the package in index.php

    index.php

    <?php
    // import package namespaces
    use League\ColorExtractor\Color;
    use League\ColorExtractor\ColorExtractor;
    use League\ColorExtractor\Palette;
    
    // if you don't use an autoloader
    // you need to require the package files
    require __DIR__ . "/Color.php";
    require __DIR__ . "/ColorExtractor.php";
    require __DIR__ . "/Palette.php";
    
    // the example from the README at ColorExtractor
    $palette = Palette::fromFilename('./testimage.png');
    // $palette is an iterator on colors sorted by pixel count
    foreach($palette as $color => $count) {
        // colors are represented by integers
        echo Color::fromIntToHex($color), ': ', $count, "
    ";
    }
    echo '<br />';
    // it offers some helpers too
    $topFive = $palette->getMostUsedColors(5);
    echo '<br />';
    echo 'top 5 most used colors:';
    echo '<pre>';
    print_r($topFive);
    echo '</pre>';
    
    $colorCount = count($palette);
    echo '<br />';
    echo "color count: " . $colorCount;
    echo '<br />';
    
    // this example gave me a 'notice: undefined offset'
    //$blackCount = $palette->getColorCount(Color::fromHexToInt('#000000'));
    //echo '<br />';
    //echo "black count " . $blackCount;
    
    
    // an extractor is built from a palette
    $extractor = new ColorExtractor($palette);
    // it defines an extract method which return the most “representative” colors
    $colors = $extractor->extract(5);
    echo '<br />';
    echo 'most representative colors:';
    echo '<pre>';
    print_r($colors);
    echo '</pre>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题