You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using keepOriginalImageFormat() on a conversion, while the conversion itself correctly generates files with the original extension (e.g., .png), the URLs generated by getUrl() still use .jpg extension.
The cause seems to be part of the Conversion constructor - it sets a default format('jpg') manipulation which isn't removed when keepOriginalImageFormat() is called.
I cannot PR this, but I suspect the fix is something like this
class Conversion
{
publicfunctionkeepOriginalImageFormat(): self
{
$this->keepOriginalImageFormat = true;
$this->removeManipulation('format'); // Add this linereturn$this;
}
}
The text was updated successfully, but these errors were encountered:
mauricekindermann
changed the title
Bug:getUrl('conversion_name') always returns .jpg when using ->keepOriginalImageFormat()
Bug: getUrl('conversion_name') always returns .jpg when using ->keepOriginalImageFormat()
Feb 13, 2025
For now I am doing this since I have a mix of imported media with original file extensions, and the default jpg conversions (which is a big "gotcha" in this library). And I have 500k files/conversions so it's not trivial to fix this in production.
class Media extends BaseMedia
{
publicfunctiongetCorrectUrl(string$conversionName = ''): string
{
if ($conversionName === '') {
return$this->getUrl();
}
$url = $this->getUrl($conversionName);
$path = $this->getPath($conversionName);
// If jpg conversion doesn't existif (!file_exists($path)) {
$originalExt = pathinfo($this->file_name, PATHINFO_EXTENSION);
$originalPath = str_replace('.jpg', '.'.$originalExt, $path);
// Check if original extension version existsif (file_exists($originalPath)) {
returnstr_replace('.jpg', '.'.$originalExt, $url);
}
// If neither exists, return original file URLreturn$this->getUrl();
}
return$url;
}
}
When using
keepOriginalImageFormat()
on a conversion, while the conversion itself correctly generates files with the original extension (e.g., .png), the URLs generated bygetUrl()
still use .jpg extension.The cause seems to be part of the
Conversion
constructor - it sets a defaultformat('jpg')
manipulation which isn't removed whenkeepOriginalImageFormat()
is called.I cannot PR this, but I suspect the fix is something like this
The text was updated successfully, but these errors were encountered: