streams/Code/Thumbs/Mp3audio.php

39 lines
959 B
PHP
Raw Normal View History

2017-11-20 23:44:25 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Thumbs;
2017-11-20 23:44:25 +00:00
use wapmorgan\Mp3Info\Mp3Info;
2017-11-20 23:44:25 +00:00
2021-12-02 23:02:31 +00:00
class Mp3audio
{
2017-11-20 23:44:25 +00:00
2021-12-02 23:02:31 +00:00
public function Match($type)
{
return (($type === 'audio/mpeg') ? true : false);
}
2017-11-20 23:44:25 +00:00
2021-12-02 23:02:31 +00:00
public function Thumb($attach, $preview_style, $height = 300, $width = 300)
{
2017-11-20 23:44:25 +00:00
$audio = new Mp3Info($attach['content'], true);
if (! $audio->hasCover) {
2021-12-02 23:02:31 +00:00
return;
}
$photo = $audio->getCover();
2017-11-20 23:44:25 +00:00
2019-07-08 06:35:24 +00:00
if ($photo) {
2021-12-02 23:02:31 +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);
2017-11-20 23:44:25 +00:00
imagedestroy($image);
2021-12-02 23:02:31 +00:00
imagejpeg($dest, dbunescbin($attach['content']) . '.thumb');
}
}
2017-11-20 23:44:25 +00:00
}