mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 14:37: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' : ''),
|
||||
'license_id' => 'required|exists:licenses,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,
|
||||
'songs' => 'required_when:track_type,2|exists:songs,id',
|
||||
'cover_id' => 'exists:images,id',
|
||||
|
|
|
@ -516,5 +516,4 @@ class ImportMLPMA extends Command
|
|||
$tags
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ use Response;
|
|||
|
||||
class ImagesController extends Controller
|
||||
{
|
||||
public function getImage($id, $type)
|
||||
public function getImage($id, $type, $extension)
|
||||
{
|
||||
$coverType = Image::getImageTypeFromName($type);
|
||||
|
||||
|
@ -56,8 +56,8 @@ class ImagesController extends Controller
|
|||
$response->header('X-Accel-Redirect', $filename);
|
||||
}
|
||||
|
||||
$response->header('Content-Disposition', "filename=\"ponyfm-i${id}-${type}.png\"");
|
||||
$response->header('Content-Type', 'image/png');
|
||||
$response->header('Content-Disposition', "filename=\"ponyfm-i${id}-${type}.{$image->extension}\"");
|
||||
$response->header('Content-Type', $image->mime);
|
||||
|
||||
$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('/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('p{id}', 'PlaylistsController@getShortlink')->where('id', '\d+');
|
||||
|
|
|
@ -78,12 +78,27 @@ class Image extends Model
|
|||
|
||||
$image->ensureDirectoryExists();
|
||||
foreach (self::$ImageTypes as $coverType) {
|
||||
$command = 'convert 2>&1 "' . $file->getPathname() . '" -background transparent -flatten +matte -strip -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'] . ' ';
|
||||
if ($coverType['id'] === self::ORIGINAL && $image->mime === 'image/jpeg') {
|
||||
$command = 'cp '.$file->getPathname().' '.$image->getFile($coverType['id']);
|
||||
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
@ -100,7 +115,7 @@ class Image extends Model
|
|||
{
|
||||
$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)
|
||||
|
@ -112,7 +127,7 @@ class Image extends Model
|
|||
{
|
||||
$typeInfo = self::$ImageTypes[$type];
|
||||
|
||||
return $this->id . '_' . $typeInfo['name'] . '.png';
|
||||
return $this->id . '_' . $typeInfo['name'] . '.'.$this->extension;
|
||||
}
|
||||
|
||||
public function getDirectory()
|
||||
|
|
|
@ -741,7 +741,7 @@ class Track extends Model
|
|||
'data' => file_get_contents($this->cover->getFile()),
|
||||
'picturetypeid' => 2,
|
||||
'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="preview" ng-class="{canOpen: isImageLoaded}" ng-click="previewImage()"><img ng-show="isImageLoaded" /></div>
|
||||
<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)" />
|
||||
</p>
|
||||
<div class="btn-group">
|
||||
|
|
|
@ -84,8 +84,8 @@ angular.module('ponyfm').directive 'pfmImageUpload', () ->
|
|||
$scope.imageObject = null
|
||||
$scope.imageFile = file
|
||||
|
||||
if file.type != 'image/png'
|
||||
$scope.error = 'Image must be a png!'
|
||||
if file.type not in ['image/png', 'image/jpeg']
|
||||
$scope.error = 'Image must be a PNG or JPEG!'
|
||||
$scope.isImageLoaded = false
|
||||
$scope.imageObject = $scope.imageFile = $scope.imageUrl = null
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue