mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-05 13:44:58 -06:00
Experimenting with a preview for attachments.
This commit is contained in:
parent
4dbc135dce
commit
1656a2f11a
@ -8,6 +8,7 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Requests\AttachmentFormRequest;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Input;
|
||||
use Preferences;
|
||||
use Session;
|
||||
@ -115,6 +116,59 @@ class AttachmentController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*/
|
||||
public function preview(AttachmentHelperInterface $helper, Attachment $attachment)
|
||||
{
|
||||
if (!function_exists('imagecreatetruecolor')) {
|
||||
abort(500);
|
||||
}
|
||||
|
||||
|
||||
$mime = $attachment->mime;
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('preview-attachment');
|
||||
$cache->addProperty($attachment->id);
|
||||
if ($cache->has()) {
|
||||
header('Content-Type: image/png');
|
||||
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
switch ($mime) {
|
||||
default:
|
||||
$img = imagecreatetruecolor(100, 10);
|
||||
imagesavealpha($img, true);
|
||||
|
||||
$trans_colour = imagecolorallocatealpha($img, 0, 0, 0, 127);
|
||||
imagefill($img, 0, 0, $trans_colour);
|
||||
header('Content-Type: image/png');
|
||||
imagepng($img);
|
||||
imagedestroy($img);
|
||||
$cache->store($img);
|
||||
exit;
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
case 'image/png':
|
||||
$img = imagecreatetruecolor(100, 100);
|
||||
$source = $helper->getAttachmentLocation($attachment);
|
||||
$decrypt = Crypt::decrypt(file_get_contents($source));
|
||||
$original = imagecreatefromstring($decrypt);
|
||||
$width = imagesx($original);
|
||||
$height = imagesy($original);
|
||||
|
||||
imagecopyresampled($img, $original, 0, 0, 0, 0, 100, 100, $width, $height);
|
||||
|
||||
header('Content-Type: image/png');
|
||||
imagepng($img);
|
||||
imagedestroy($img);
|
||||
exit;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param AttachmentFormRequest $request
|
||||
|
@ -93,7 +93,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<i class="fa {{ att.mime|mimeIcon }}"></i>
|
||||
<a href="{{ route('attachments.download', att.id) }}" title="{{ att.filename }}">
|
||||
<a href="{{ route('attachments.download', att.id) }}" tle="{{ att.filename }}">
|
||||
{% if att.title %}
|
||||
{{ att.title }}
|
||||
{% else %}
|
||||
@ -106,6 +106,9 @@
|
||||
<em>{{ att.description }}</em>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td style="width:100px;">
|
||||
<img src="{{ route('attachments.preview', att.id) }}"></img>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user