$info = @getimagesize($this->filepath);
- if (!(
- ($info[2] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) ||
- ($info[2] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) ||
- $info[2] == IMAGETYPE_BMP ||
- ($info[2] == IMAGETYPE_WBMP && function_exists('imagecreatefromwbmp')) ||
- ($info[2] == IMAGETYPE_XBM && function_exists('imagecreatefromxbm')) ||
- ($info[2] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')))) {
+ if (
+ ($info[2] == IMAGETYPE_GIF && !function_exists('imagecreatefromgif')) ||
+ ($info[2] == IMAGETYPE_JPEG && !function_exists('imagecreatefromjpeg')) ||
+ ($info[2] == IMAGETYPE_WBMP && !function_exists('imagecreatefromwbmp')) ||
+ ($info[2] == IMAGETYPE_XBM && !function_exists('imagecreatefromxbm')) ||
+ ($info[2] == IMAGETYPE_PNG && !function_exists('imagecreatefrompng'))) {
// TRANS: Exception thrown when trying to upload an unsupported image file format.
throw new UnsupportedMediaException(_('Unsupported image format.'), $this->filepath);
if (empty($file->filename)) {
throw new UnsupportedMediaException(_('File without filename could not get a thumbnail source.'));
}
+
+ // First some mimetype specific exceptions
+ switch ($file->mimetype) {
+ case 'image/svg+xml':
+ throw new UseFileAsThumbnailException($file->id);
+ }
+
+ // And we'll only consider it an image if it has such a media type
switch ($media) {
case 'image':
$imgPath = $file->getPath();
return new ImageFile(null, $_FILES[$param]['tmp_name']);
}
- /**
- * Compat interface for old code generating avatar thumbnails...
- * Saves the scaled file directly into the avatar area.
- *
- * @param int $size target width & height -- must be square
- * @param int $x (default 0) upper-left corner to crop from
- * @param int $y (default 0) upper-left corner to crop from
- * @param int $w (default full) width of image area to crop
- * @param int $h (default full) height of image area to crop
- * @return string filename
- */
- function resize($size, $x = 0, $y = 0, $w = null, $h = null)
- {
- $targetType = $this->preferredType();
- $outname = Avatar::filename($this->id,
- image_type_to_extension($targetType),
- $size,
- common_timestamp());
- $outpath = Avatar::path($outname);
- $this->resizeTo($outpath, array('width'=>$size, 'height'=>$size,
- 'x'=>$x, 'y'=>$y,
- 'w'=>$w, 'h'=>$h));
- return $outname;
- }
-
/**
* Copy the image file to the given destination.
*
if ($this->rotate == 0) {
// No rotational difference, just copy it as-is
@copy($this->filepath, $outpath);
+
+ // And set chmod
+ @chmod($outpath, common_config('attachments', 'chmod'));
return $outpath;
} elseif (abs($this->rotate) == 90) {
// Box is rotated 90 degrees in either direction,
throw new Exception(_('Unknown file type'));
}
+ // Always chmod 0644 (default) to have other processes (e.g. queue daemon read it)
+ @chmod($outpath, common_config('attachments', 'chmod'));
+
imagedestroy($image_src);
imagedestroy($image_dest);
}