streams/Zotlabs/Thumbs/Mp3audio.php

44 lines
954 B
PHP
Raw Normal View History

2017-11-20 23:44:25 +00:00
<?php
namespace Zotlabs\Thumbs;
2020-02-05 03:51:35 +00:00
use PhpId3\Id3TagsReader;
2017-11-20 23:44:25 +00:00
class Mp3audio {
function Match($type) {
return(($type === 'audio/mpeg') ? true : false );
}
function Thumb($attach,$preview_style,$height = 300, $width = 300) {
2020-02-05 03:51:35 +00:00
$fh = @fopen(dbunescbin($attach['content']),'rb');
if ($fh === false) {
return;
}
$id3 = new Id3TagsReader($fh);
$id3->readAllTags();
2017-11-20 23:44:25 +00:00
2020-02-05 03:51:35 +00:00
$image = $id3->getImage();
if (is_array($image)) {
$photo = $image[1];
}
2017-11-20 23:44:25 +00:00
2020-02-05 03:51:35 +00:00
fclose($fh);
2019-07-08 06:35:24 +00:00
if ($photo) {
2017-11-20 23:44:25 +00:00
$image = imagecreatefromstring($photo);
$dest = imagecreatetruecolor( $width, $height );
$srcwidth = imagesx($image);
$srcheight = imagesy($image);
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopyresampled($dest, $image, 0, 0, 0, 0, $width, $height, $srcwidth, $srcheight);
imagedestroy($image);
imagejpeg($dest,dbunescbin($attach['content']) . '.thumb');
}
}
}