Skip to content

Commit

Permalink
Thumbhash::encode -> Thumbhash::RGBAToHash
Browse files Browse the repository at this point in the history
  • Loading branch information
SRWieZ committed Mar 24, 2023
1 parent bb4076a commit 79203b1
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$content = file_get_contents($path);

list($width, $height, $pixels) = extract_size_and_pixels_with_imagick($content);
$hash = Thumbhash::encode($width, $height, $pixels);
$hash = Thumbhash::RGBAToHash($width, $height, $pixels);

$thumbBase64 = rtrim(base64_encode(implode(array_map("chr", $hash))), '=');
$data_url = Thumbhash::toDataURL($hash);
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ composer require srwiez/thumbhash
To generate a thumbhash for an image file, you can use the Thumbhash\Thumbhash class:

Example to show a thumbhash image from a local file

```php
use Thumbhash\Thumbhash;

$content = file_get_contents($url);

list($width, $height, $pixels) = extract_size_and_pixels_with_imagick($content);

$hash = Thumbhash::encode($width, $height, $pixels);
$hash = Thumbhash::RGBAToHash($width, $height, $pixels);
$key = Thumbhash::convertHashToString($hash); // You can store this in your database as a string
$url = Thumbhash::toDataURL($hash);

Expand Down
18 changes: 0 additions & 18 deletions src/Color.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Thumbhash.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Thumbhash
* @returns array The ThumbHash as an array.
*/

public static function encode($w, $h, $rgba)
public static function RGBAToHash($w, $h, $rgba)
{
// Encoding an image larger than 100x100 is slow with no benefit
if ($w > 100 || $h > 100) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/ThumbhashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

list($width, $height, $pixels) = extract_size_and_pixels_with_imagick($content);

$encoded = Thumbhash::encode($width, $height, $pixels);
$encoded = Thumbhash::RGBAToHash($width, $height, $pixels);
$encodedBase64 = Thumbhash::convertHashToString($encoded);

expect($encodedBase64)->toBe($hash);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/UnitTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

it('throws exception if pixel width or height > 100 ', function () {
\Thumbhash\Thumbhash::encode(101, 100, []);
\Thumbhash\Thumbhash::RGBAToHash(101, 100, []);
})->throws(Exception::class);

0 comments on commit 79203b1

Please sign in to comment.