Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setMediaFolder example
if
(
$media
->
getMediaFolder
(
)
!== null
)
{
return
;
}
$criteria
=
new
Criteria
(
[
$mediaFolderId
]
)
;
$criteria
->
addAssociation
(
'configuration.mediaThumbnailSizes'
)
;
/** @var MediaFolderEntity $folder */
$folder
=
$this
->mediaFolderRepository->
search
(
$criteria
,
$context
)
->
get
(
$mediaFolderId
)
;
$media
->
setMediaFolder
(
$folder
)
;
}
private
function
getImageResource
(
MediaEntity
$media
)
: \GdImage
{
$filePath
=
$this
->urlGenerator->
getRelativeMediaUrl
(
$media
)
;
/** @var string $file */
$file
=
$this
->
getFileSystem
(
$media
)
->
read
(
$filePath
)
;
$image
= @
imagecreatefromstring
(
$file
)
;
if
(
$image
=== false
)
{
throw
MediaException::
thumbnailNotSupported
(
$media
->
getId
(
)
)
;
}