thephpleague/color-extractor 可以不用 autoload.php (作曲家)吗?

Can thephpleague/color-extractor be used without autoload.php (composer)?

我正在尝试使用 color-extractor 获取图像的颜色,但我无法正常工作。

我注意到包中缺少 autoload.php 文件,经过一些谷歌搜索后,似乎需要您使用 Composer。我没有使用过 composer,也没有太多使用命令行的经验。我正在做的事情,但希望在使用这个 php 包之前不必学习所有内容。

我尝试更改其中的一些 php 行:

require 'vendor/autoload.php';

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

对此:

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

但它没有用,我得到了这些错误:

[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

是否可以在不学习和使用 composer 的情况下使用此包?如果可以,我将如何 require/include 文件?

谢谢!

希望这对您有所帮助。

创建一个项目文件夹,例如“颜色提取器”

复制粘贴 thephpleague/color-extractor/src/League/ColorExtractor

中的 3 个文件
  1. Color.php
  2. ColorExtractor.php
  3. Palette.php

进入你的项目文件夹。

然后创建一个 index.php 文件(见下文),该文件将 运行 thephpleague/color-extractor 自述文件中的示例 – 以确保一切按预期工作。

您的项目文件夹应包含以下内容:

注意:我在index.php

中使用了'testimage.png'来测试包

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, "\n";
}
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>';