mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 13:07:59 +01:00
Added support for JPEG cover art.
This commit is contained in:
parent
17810942b4
commit
93b76d1954
8 changed files with 30 additions and 16 deletions
|
@ -65,7 +65,7 @@ class EditTrackCommand extends CommandBase
|
||||||
time() + (86400 * 2))) . (isset($this->_input['released_at']) && $this->_input['released_at'] != "" ? '|date' : ''),
|
time() + (86400 * 2))) . (isset($this->_input['released_at']) && $this->_input['released_at'] != "" ? '|date' : ''),
|
||||||
'license_id' => 'required|exists:licenses,id',
|
'license_id' => 'required|exists:licenses,id',
|
||||||
'genre_id' => 'required|exists:genres,id',
|
'genre_id' => 'required|exists:genres,id',
|
||||||
'cover' => 'image|mimes:png|min_width:350|min_height:350',
|
'cover' => 'image|mimes:png,jpeg|min_width:350|min_height:350',
|
||||||
'track_type_id' => 'required|exists:track_types,id|not_in:'.TrackType::UNCLASSIFIED_TRACK,
|
'track_type_id' => 'required|exists:track_types,id|not_in:'.TrackType::UNCLASSIFIED_TRACK,
|
||||||
'songs' => 'required_when:track_type,2|exists:songs,id',
|
'songs' => 'required_when:track_type,2|exists:songs,id',
|
||||||
'cover_id' => 'exists:images,id',
|
'cover_id' => 'exists:images,id',
|
||||||
|
|
|
@ -516,5 +516,4 @@ class ImportMLPMA extends Command
|
||||||
$tags
|
$tags
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ use Response;
|
||||||
|
|
||||||
class ImagesController extends Controller
|
class ImagesController extends Controller
|
||||||
{
|
{
|
||||||
public function getImage($id, $type)
|
public function getImage($id, $type, $extension)
|
||||||
{
|
{
|
||||||
$coverType = Image::getImageTypeFromName($type);
|
$coverType = Image::getImageTypeFromName($type);
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ class ImagesController extends Controller
|
||||||
$response->header('X-Accel-Redirect', $filename);
|
$response->header('X-Accel-Redirect', $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$response->header('Content-Disposition', "filename=\"ponyfm-i${id}-${type}.png\"");
|
$response->header('Content-Disposition', "filename=\"ponyfm-i${id}-${type}.{$image->extension}\"");
|
||||||
$response->header('Content-Type', 'image/png');
|
$response->header('Content-Type', $image->mime);
|
||||||
|
|
||||||
$lastModified = filemtime($filename);
|
$lastModified = filemtime($filename);
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ Route::get('/about', function() { return View::make('pages.about'); });
|
||||||
Route::get('/faq', function() { return View::make('pages.faq'); });
|
Route::get('/faq', function() { return View::make('pages.faq'); });
|
||||||
Route::get('/mlpforums-advertising-program', function() { return View::make('pages.mlpforums-advertising-program'); });
|
Route::get('/mlpforums-advertising-program', function() { return View::make('pages.mlpforums-advertising-program'); });
|
||||||
|
|
||||||
Route::get('i{id}/{type}.png', 'ImagesController@getImage')->where('id', '\d+');
|
Route::get('i{id}/{type}.{extension}', 'ImagesController@getImage')->where('id', '\d+');
|
||||||
|
|
||||||
Route::get('playlist/{id}-{slug}', 'PlaylistsController@getPlaylist');
|
Route::get('playlist/{id}-{slug}', 'PlaylistsController@getPlaylist');
|
||||||
Route::get('p{id}', 'PlaylistsController@getShortlink')->where('id', '\d+');
|
Route::get('p{id}', 'PlaylistsController@getShortlink')->where('id', '\d+');
|
||||||
|
|
|
@ -78,12 +78,27 @@ class Image extends Model
|
||||||
|
|
||||||
$image->ensureDirectoryExists();
|
$image->ensureDirectoryExists();
|
||||||
foreach (self::$ImageTypes as $coverType) {
|
foreach (self::$ImageTypes as $coverType) {
|
||||||
$command = 'convert 2>&1 "' . $file->getPathname() . '" -background transparent -flatten +matte -strip -quality 95 -format png ';
|
if ($coverType['id'] === self::ORIGINAL && $image->mime === 'image/jpeg') {
|
||||||
if (isset($coverType['width']) && isset($coverType['height'])) {
|
$command = 'cp '.$file->getPathname().' '.$image->getFile($coverType['id']);
|
||||||
$command .= '-thumbnail ' . $coverType['width'] . 'x' . $coverType['height'] . '^ -gravity center -extent ' . $coverType['width'] . 'x' . $coverType['height'] . ' ';
|
|
||||||
|
} else {
|
||||||
|
// ImageMagick options reference: http://www.imagemagick.org/script/command-line-options.php
|
||||||
|
$command = 'convert 2>&1 "' . $file->getPathname() . '" -background white -alpha remove -alpha off -strip';
|
||||||
|
|
||||||
|
if ($image->mime === 'image/jpeg') {
|
||||||
|
$command .= ' -quality 100 -format jpeg';
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$command .= ' -quality 95 -format png';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($coverType['width']) && isset($coverType['height'])) {
|
||||||
|
$command .= " -thumbnail ${coverType['width']}x${coverType['height']}^ -gravity center -extent ${coverType['width']}x${coverType['height']}";
|
||||||
|
}
|
||||||
|
|
||||||
|
$command .= ' "' . $image->getFile($coverType['id']) . '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
$command .= '"' . $image->getFile($coverType['id']) . '"';
|
|
||||||
External::execute($command);
|
External::execute($command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +115,7 @@ class Image extends Model
|
||||||
{
|
{
|
||||||
$type = self::$ImageTypes[$type];
|
$type = self::$ImageTypes[$type];
|
||||||
|
|
||||||
return action('ImagesController@getImage', ['id' => $this->id, 'type' => $type['name']]);
|
return action('ImagesController@getImage', ['id' => $this->id, 'type' => $type['name'], 'extension' => $this->extension]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFile($type = self::NORMAL)
|
public function getFile($type = self::NORMAL)
|
||||||
|
@ -112,7 +127,7 @@ class Image extends Model
|
||||||
{
|
{
|
||||||
$typeInfo = self::$ImageTypes[$type];
|
$typeInfo = self::$ImageTypes[$type];
|
||||||
|
|
||||||
return $this->id . '_' . $typeInfo['name'] . '.png';
|
return $this->id . '_' . $typeInfo['name'] . '.'.$this->extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDirectory()
|
public function getDirectory()
|
||||||
|
|
|
@ -741,7 +741,7 @@ class Track extends Model
|
||||||
'data' => file_get_contents($this->cover->getFile()),
|
'data' => file_get_contents($this->cover->getFile()),
|
||||||
'picturetypeid' => 2,
|
'picturetypeid' => 2,
|
||||||
'description' => 'cover',
|
'description' => 'cover',
|
||||||
'mime' => 'image/png'
|
'mime' => $this->cover->mime
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="image-upload" ng-class="{'has-error': error != null}">
|
<div class="image-upload" ng-class="{'has-error': error != null}">
|
||||||
<div class="preview" ng-class="{canOpen: isImageLoaded}" ng-click="previewImage()"><img ng-show="isImageLoaded" /></div>
|
<div class="preview" ng-class="{canOpen: isImageLoaded}" ng-click="previewImage()"><img ng-show="isImageLoaded" /></div>
|
||||||
<p>
|
<p>
|
||||||
Image must be a PNG that is at least 350x350. <br />
|
Image must be a PNG or JPEG that is at least 350x350. <br />
|
||||||
<input type="file" onchange="angular.element(this).scope().setImageFile(this)" />
|
<input type="file" onchange="angular.element(this).scope().setImageFile(this)" />
|
||||||
</p>
|
</p>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
|
|
@ -84,8 +84,8 @@ angular.module('ponyfm').directive 'pfmImageUpload', () ->
|
||||||
$scope.imageObject = null
|
$scope.imageObject = null
|
||||||
$scope.imageFile = file
|
$scope.imageFile = file
|
||||||
|
|
||||||
if file.type != 'image/png'
|
if file.type not in ['image/png', 'image/jpeg']
|
||||||
$scope.error = 'Image must be a png!'
|
$scope.error = 'Image must be a PNG or JPEG!'
|
||||||
$scope.isImageLoaded = false
|
$scope.isImageLoaded = false
|
||||||
$scope.imageObject = $scope.imageFile = $scope.imageUrl = null
|
$scope.imageObject = $scope.imageFile = $scope.imageUrl = null
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue