[AVATAR] Temporary ImageFile wasn't
This commit is contained in:
parent
44ad0d3a85
commit
02055dee49
|
@ -359,7 +359,7 @@ class AvatarsettingsAction extends SettingsAction
|
||||||
'x' => $dest_x, 'y' => $dest_y,
|
'x' => $dest_x, 'y' => $dest_y,
|
||||||
'w' => $dest_w, 'h' => $dest_h,];
|
'w' => $dest_w, 'h' => $dest_h,];
|
||||||
|
|
||||||
$imagefile = new ImageFile(null, $filedata['filepath']);
|
$imagefile = new ImageFile(-1, $filedata['filepath']);
|
||||||
$filename = Avatar::filename(
|
$filename = Avatar::filename(
|
||||||
$this->scoped->getID(),
|
$this->scoped->getID(),
|
||||||
image_type_to_extension($imagefile->preferredType()),
|
image_type_to_extension($imagefile->preferredType()),
|
||||||
|
|
|
@ -55,7 +55,21 @@ class ImageFile extends MediaFile
|
||||||
public $animated; // Animated image? (has more than 1 frame). null means untested
|
public $animated; // Animated image? (has more than 1 frame). null means untested
|
||||||
public $mimetype; // The _ImageFile_ mimetype, _not_ the originating File object
|
public $mimetype; // The _ImageFile_ mimetype, _not_ the originating File object
|
||||||
|
|
||||||
public function __construct($id, string $filepath)
|
/**
|
||||||
|
* ImageFile constructor.
|
||||||
|
*
|
||||||
|
* @param int|null $id The DB id of the file. Int if known, null if not.
|
||||||
|
* If null, it searches for it. If -1, it skips all DB
|
||||||
|
* interactions (useful for temporary objects)
|
||||||
|
* @param string $filepath The path of the file this media refers to. Required
|
||||||
|
* @param string|null $filehash The hash of the file, if known. Optional
|
||||||
|
*
|
||||||
|
* @throws ClientException
|
||||||
|
* @throws NoResultException
|
||||||
|
* @throws ServerException
|
||||||
|
* @throws UnsupportedMediaException
|
||||||
|
*/
|
||||||
|
public function __construct(?int $id = null, string $filepath, ?string $filehash = null)
|
||||||
{
|
{
|
||||||
$old_limit = ini_set('memory_limit', common_config('attachments', 'memory_limit'));
|
$old_limit = ini_set('memory_limit', common_config('attachments', 'memory_limit'));
|
||||||
|
|
||||||
|
@ -74,7 +88,14 @@ class ImageFile extends MediaFile
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if (!(($cmp($this, IMAGETYPE_GIF) && function_exists('imagecreatefromgif')) || ($cmp($this, IMAGETYPE_JPEG) && function_exists('imagecreatefromjpeg')) || ($cmp($this, IMAGETYPE_BMP) && function_exists('imagecreatefrombmp')) || ($cmp($this, IMAGETYPE_WBMP) && function_exists('imagecreatefromwbmp')) || ($cmp($this, IMAGETYPE_XBM) && function_exists('imagecreatefromxbm')) || ($cmp($this, IMAGETYPE_PNG) && function_exists('imagecreatefrompng')))) {
|
if (!(($cmp($this, IMAGETYPE_GIF) && function_exists('imagecreatefromgif')) ||
|
||||||
|
($cmp($this, IMAGETYPE_JPEG) && function_exists('imagecreatefromjpeg')) ||
|
||||||
|
($cmp($this, IMAGETYPE_BMP) && function_exists('imagecreatefrombmp')) ||
|
||||||
|
($cmp($this, IMAGETYPE_WBMP) && function_exists('imagecreatefromwbmp')) ||
|
||||||
|
($cmp($this, IMAGETYPE_XBM) && function_exists('imagecreatefromxbm')) ||
|
||||||
|
($cmp($this, IMAGETYPE_PNG) && function_exists('imagecreatefrompng'))
|
||||||
|
)
|
||||||
|
) {
|
||||||
common_debug("Mimetype '{$this->mimetype}' was not recognized as a supported format");
|
common_debug("Mimetype '{$this->mimetype}' was not recognized as a supported format");
|
||||||
// TRANS: Exception thrown when trying to upload an unsupported image file format.
|
// TRANS: Exception thrown when trying to upload an unsupported image file format.
|
||||||
throw new UnsupportedMediaException(_m('Unsupported image format.'), $this->filepath);
|
throw new UnsupportedMediaException(_m('Unsupported image format.'), $this->filepath);
|
||||||
|
@ -86,7 +107,7 @@ class ImageFile extends MediaFile
|
||||||
parent::__construct(
|
parent::__construct(
|
||||||
$filepath,
|
$filepath,
|
||||||
$this->mimetype,
|
$this->mimetype,
|
||||||
null /* filehash, MediaFile will calculate it */,
|
$filehash,
|
||||||
$id
|
$id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -123,7 +144,11 @@ class ImageFile extends MediaFile
|
||||||
/**
|
/**
|
||||||
* Create a thumbnail from a file object
|
* Create a thumbnail from a file object
|
||||||
*
|
*
|
||||||
|
* @param File $file
|
||||||
* @return ImageFile
|
* @return ImageFile
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws UnsupportedMediaException
|
||||||
|
* @throws UseFileAsThumbnailException
|
||||||
*/
|
*/
|
||||||
public static function fromFileObject(File $file)
|
public static function fromFileObject(File $file)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,10 +44,12 @@ class MediaFile
|
||||||
public $mimetype;
|
public $mimetype;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* MediaFile constructor.
|
||||||
|
*
|
||||||
* @param string $filepath The path of the file this media refers to. Required
|
* @param string $filepath The path of the file this media refers to. Required
|
||||||
* @param string $mimetype The mimetype of the file. Required
|
* @param string $mimetype The mimetype of the file. Required
|
||||||
* @param string $filehash The hash of the file, if known. Optional
|
* @param string|null $filehash The hash of the file, if known. Optional
|
||||||
* @param null|int $id The DB id of the file. Int if known, null if not.
|
* @param int|null $id The DB id of the file. Int if known, null if not.
|
||||||
* If null, it searches for it. If -1, it skips all DB
|
* If null, it searches for it. If -1, it skips all DB
|
||||||
* interactions (useful for temporary objects)
|
* interactions (useful for temporary objects)
|
||||||
*
|
*
|
||||||
|
@ -55,7 +57,7 @@ class MediaFile
|
||||||
* @throws NoResultException
|
* @throws NoResultException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public function __construct(string $filepath, string $mimetype, $filehash = null, $id = null)
|
public function __construct(string $filepath, string $mimetype, ?string $filehash = null, ?int $id = null)
|
||||||
{
|
{
|
||||||
$this->filepath = $filepath;
|
$this->filepath = $filepath;
|
||||||
$this->filename = basename($this->filepath);
|
$this->filename = basename($this->filepath);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user