mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-02-21 12:24:22 +01:00
All images now have colour palettes
This commit is contained in:
parent
4e2b2f90ec
commit
40f5d0721e
3 changed files with 47 additions and 0 deletions
|
@ -25,6 +25,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
use Config;
|
use Config;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
use ColorThief\ColorThief;
|
||||||
|
use Helpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Poniverse\Ponyfm\Models\Image
|
* Poniverse\Ponyfm\Models\Image
|
||||||
|
@ -36,6 +38,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
* @property integer $size
|
* @property integer $size
|
||||||
* @property string $hash
|
* @property string $hash
|
||||||
* @property integer $uploaded_by
|
* @property integer $uploaded_by
|
||||||
|
* @property string $palette
|
||||||
* @property \Carbon\Carbon $created_at
|
* @property \Carbon\Carbon $created_at
|
||||||
* @property \Carbon\Carbon $updated_at
|
* @property \Carbon\Carbon $updated_at
|
||||||
* @method static \Illuminate\Database\Query\Builder|\Poniverse\Ponyfm\Models\Image whereId($value)
|
* @method static \Illuminate\Database\Query\Builder|\Poniverse\Ponyfm\Models\Image whereId($value)
|
||||||
|
@ -191,4 +194,15 @@ class Image extends Model
|
||||||
mkdir($destination, 0777, true);
|
mkdir($destination, 0777, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPalette() {
|
||||||
|
if ($this->palette === null) {
|
||||||
|
$palette = ColorThief::getPalette($this->getFile(Image::NORMAL), 2);
|
||||||
|
$formatted_palette = array_map("Helpers::rgb2hex", $palette);
|
||||||
|
$this->palette = json_encode($formatted_palette);
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_decode($this->palette);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -500,6 +500,7 @@ class Track extends Model implements Searchable, Commentable, Favouritable
|
||||||
'normal' => $track->getCoverUrl(Image::NORMAL),
|
'normal' => $track->getCoverUrl(Image::NORMAL),
|
||||||
'original' => $track->getCoverUrl(Image::ORIGINAL)
|
'original' => $track->getCoverUrl(Image::ORIGINAL)
|
||||||
],
|
],
|
||||||
|
'cover_colors' => $track->cover->getPalette(),
|
||||||
'streams' => [
|
'streams' => [
|
||||||
'mp3' => $track->getStreamUrl('MP3'),
|
'mp3' => $track->getStreamUrl('MP3'),
|
||||||
'aac' => (!Config::get('app.debug') || is_file($track->getFileFor('AAC'))) ? $track->getStreamUrl('AAC') : null,
|
'aac' => (!Config::get('app.debug') || is_file($track->getFileFor('AAC'))) ? $track->getStreamUrl('AAC') : null,
|
||||||
|
|
32
database/migrations/2017_05_19_124056_AddPaletteToImages.php
Normal file
32
database/migrations/2017_05_19_124056_AddPaletteToImages.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AddPaletteToImages extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('images', function(Blueprint $table) {
|
||||||
|
$table->json('palette')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('images', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['palette']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue