Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getThumbnailQuality example
private
function
assertConfig
(
MediaFolderEntity
$folder
,
bool
$useParentConfiguration
,
bool
$createThumbnails
,
bool
$keepAspectRatio
,
int
$thumbnailQuality
)
: void
{
static
::
assertEquals
(
$useParentConfiguration
,
$folder
->
getUseParentConfiguration
(
)
)
;
static
::
assertEquals
(
$createThumbnails
,
$folder
->
getConfiguration
(
)
?->
getCreateThumbnails
(
)
)
;
static
::
assertEquals
(
$keepAspectRatio
,
$folder
->
getConfiguration
(
)
?->
getKeepAspectRatio
(
)
)
;
static
::
assertEquals
(
$thumbnailQuality
,
$folder
->
getConfiguration
(
)
?->
getThumbnailQuality
(
)
)
;
}
private
function
assertConfigIsSame
(
MediaFolderEntity
$folder
, MediaFolderEntity
$childFolder
)
: void
{
static
::
assertEquals
(
$folder
->
getConfigurationId
(
)
,
$childFolder
->
getConfigurationId
(
)
)
;
}
}
try
{
foreach
(
$thumbnailSizes
as
$size
)
{
$thumbnailSize
=
$this
->
calculateThumbnailSize
(
$originalImageSize
,
$size
,
$config
)
;
$thumbnail
=
$this
->
createNewImage
(
$mediaImage
,
$type
,
$originalImageSize
,
$thumbnailSize
)
;
$url
=
$this
->urlGenerator->
getRelativeThumbnailUrl
(
$media
,
(
new
MediaThumbnailEntity
(
)
)
->
assign
(
[
'width' =>
$size
->
getWidth
(
)
, 'height' =>
$size
->
getHeight
(
)
]
)
)
;
$this
->
writeThumbnail
(
$thumbnail
,
$media
,
$url
,
$config
->
getThumbnailQuality
(
)
)
;
$mediaFilesystem
=
$this
->
getFileSystem
(
$media
)
;
if
(
$originalImageSize
===
$thumbnailSize
&&
$mediaFilesystem
->
fileSize
(
$originalUrl
)
<
$mediaFilesystem
->
fileSize
(
$url
)
)
{
$mediaFilesystem
->
write
(
$url
,
$mediaFilesystem
->
read
(
$originalUrl
)
)
;
}
$savedThumbnails
[
]
=
[
'mediaId' =>
$media
->
getId
(
)
,
'width' =>
$size
->
getWidth
(
)
,
'height' =>
$size
->
getHeight
(
)
,
]
;
throw
new
Exception
(
sprintf
(
'File %s is not an image.',
$imagePath
)
)
;
}
if
(
empty
(
$thumbnailSizes
)
)
{
$thumbnailSizes
=
$this
->
getThumbnailSizesFromMedia
(
$media
)
;
$thumbnailSizes
=
array_merge
(
$thumbnailSizes
,
$media
->
getDefaultThumbnails
(
)
)
;
}
$albumSettings
=
$this
->
getAlbumSettingsFromMedia
(
$media
)
;
if
(
$albumSettings
)
{
$highDpi
=
$albumSettings
->
isThumbnailHighDpi
(
)
;
$standardQuality
=
$albumSettings
->
getThumbnailQuality
(
)
;
$highDpiQuality
=
$albumSettings
->
getThumbnailHighDpiQuality
(
)
;
}
else
{
$highDpi
= false;
$standardQuality
= 90;
$highDpiQuality
= 90;
}
if
(
$standardQuality
=== null
)
{
$standardQuality
= 90;
}
$thumbnailQuality
=
$data
[
'thumbnailQuality'
]
?? 90;
$thumbnailHighDpiQuality
=
$data
[
'thumbnailHighDpiQuality'
]
?? 70;
$albumId
=
$album
->
getId
(
)
;
if
(
empty
(
$albumId
)
&&
$data
[
'parent'
]
!== null
)
{
/** @var Settings $parentSettings */
$parentSettings
=
$data
[
'parent'
]
->
getSettings
(
)
;
$thumbnailSizes
=
$parentSettings
->
getThumbnailSize
(
)
;
$thumbnailHighDpi
=
$parentSettings
->
isThumbnailHighDpi
(
)
;
$thumbnailHighDpiQuality
=
$parentSettings
->
getThumbnailHighDpiQuality
(
)
;
$thumbnailQuality
=
$parentSettings
->
getThumbnailQuality
(
)
;
$createThumbnails
=
$parentSettings
->
getCreateThumbnails
(
)
;
}
$settings
->
setCreateThumbnails
(
$createThumbnails
)
;
$settings
->
setThumbnailSize
(
empty
(
$thumbnailSizes
)
? '' :
$thumbnailSizes
)
;
$settings
->
setThumbnailHighDpi
(
$thumbnailHighDpi
)
;
$settings
->
setThumbnailQuality
(
$thumbnailQuality
)
;
$settings
->
setThumbnailHighDpiQuality
(
$thumbnailHighDpiQuality
)
;
$settings
->
setIcon
(
$icon
)
;
$data
[
'settings'
]
=
$settings
;