Replies: 1 comment
-
Feel free to submit a PR that improves this 👍 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a model that has a media collection for PDFs. I've registered a simple 150x200 "thumbnail" conversion to the collection. When a PDF is added to the collection, the thumbnail is generated without any problems. However, I am unable to render the "thumbnail" conversion.
This is in my view:
$media->hasGeneratedConversion('thumbnail') === true
because, as I already mentioned, the conversion ran just fine:The problem is that
$media('thumbnail')
returns an empty string because of the conditional in\Spatie\MediaLibrary\MediaCollections\HtmlableMedia::toHtml()
:It is checking the mime type of the original media, not the converted media. The original media is a PDF and
\Spatie\MediaLibrary\Conversions\ImageGenerators\Image
only handles image mime types, sotoHtml()
returns an empty string.I put together a simple example you can run to recreate it. You just need to change the IDs in the
find()
calls.Here is my output:
Note that on "pdf" there is a "thumbnail_url" value but there is not a "thumbnail_html" value.
For further confirmation, I made the conditional return the string "nope":
I can get the conversion URL and output the
<img>
myself, of course. I'd prefer to use the built-in way of rendering though 😉Thanks!
Beta Was this translation helpful? Give feedback.
All reactions