Magento 2 - GIF Images , Animation is not working on frontend
I am trying to upload .gif image for few products , image is uploading from admin panel successfully
and animation also working in admin panel.
But issue here is when i am checking this product on frontend - image is displayed but Animation is not working on frontend
I have also check same issue on github - https://github.com/magento/magento2/issues/8015
But unable to find any solution.
product-images magento-2.1.8
add a comment |
I am trying to upload .gif image for few products , image is uploading from admin panel successfully
and animation also working in admin panel.
But issue here is when i am checking this product on frontend - image is displayed but Animation is not working on frontend
I have also check same issue on github - https://github.com/magento/magento2/issues/8015
But unable to find any solution.
product-images magento-2.1.8
Check this one may be help to you : magento.stackexchange.com/questions/189531/…
– Suresh Chikani
Aug 21 '17 at 8:49
@SHPatel Thanks , i have already checked that , but needed better solution for this
– Manthan Dave
Aug 21 '17 at 8:50
add a comment |
I am trying to upload .gif image for few products , image is uploading from admin panel successfully
and animation also working in admin panel.
But issue here is when i am checking this product on frontend - image is displayed but Animation is not working on frontend
I have also check same issue on github - https://github.com/magento/magento2/issues/8015
But unable to find any solution.
product-images magento-2.1.8
I am trying to upload .gif image for few products , image is uploading from admin panel successfully
and animation also working in admin panel.
But issue here is when i am checking this product on frontend - image is displayed but Animation is not working on frontend
I have also check same issue on github - https://github.com/magento/magento2/issues/8015
But unable to find any solution.
product-images magento-2.1.8
product-images magento-2.1.8
edited Aug 21 '17 at 8:50
Manthan Dave
asked Aug 21 '17 at 8:31
Manthan DaveManthan Dave
7,70421438
7,70421438
Check this one may be help to you : magento.stackexchange.com/questions/189531/…
– Suresh Chikani
Aug 21 '17 at 8:49
@SHPatel Thanks , i have already checked that , but needed better solution for this
– Manthan Dave
Aug 21 '17 at 8:50
add a comment |
Check this one may be help to you : magento.stackexchange.com/questions/189531/…
– Suresh Chikani
Aug 21 '17 at 8:49
@SHPatel Thanks , i have already checked that , but needed better solution for this
– Manthan Dave
Aug 21 '17 at 8:50
Check this one may be help to you : magento.stackexchange.com/questions/189531/…
– Suresh Chikani
Aug 21 '17 at 8:49
Check this one may be help to you : magento.stackexchange.com/questions/189531/…
– Suresh Chikani
Aug 21 '17 at 8:49
@SHPatel Thanks , i have already checked that , but needed better solution for this
– Manthan Dave
Aug 21 '17 at 8:50
@SHPatel Thanks , i have already checked that , but needed better solution for this
– Manthan Dave
Aug 21 '17 at 8:50
add a comment |
2 Answers
2
active
oldest
votes
So finally i got the solution for the same ,and resolved the issue
looking at the code i found that magento encoding image path in md5 string as well
if you have seen path on product detail page it is like - catalog/product/cache/image/700x560/e9c3970ab036de70892d86c6d221abfe/m/b/
so here i have override the model Image.php in my custom module and for specifically GIF image i have removed that md5 encryption code and call image path directly.
Below is the code :
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCatalogModelProductImage" type="ProductAjaxAnimationModelImage" />
</config>
image.php - overrided function setBaseFile.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
}
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
Hope it helps :)
add a comment |
A correction here. If you use above script in image.php, GIF will start working no doubt, but i check is that after that user is not able to upload jpeg or png anymore. Below is that updated version of it with bug fix. I know its late, but hope it helps.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
}
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f189888%2fmagento-2-gif-images-animation-is-not-working-on-frontend%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
So finally i got the solution for the same ,and resolved the issue
looking at the code i found that magento encoding image path in md5 string as well
if you have seen path on product detail page it is like - catalog/product/cache/image/700x560/e9c3970ab036de70892d86c6d221abfe/m/b/
so here i have override the model Image.php in my custom module and for specifically GIF image i have removed that md5 encryption code and call image path directly.
Below is the code :
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCatalogModelProductImage" type="ProductAjaxAnimationModelImage" />
</config>
image.php - overrided function setBaseFile.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
}
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
Hope it helps :)
add a comment |
So finally i got the solution for the same ,and resolved the issue
looking at the code i found that magento encoding image path in md5 string as well
if you have seen path on product detail page it is like - catalog/product/cache/image/700x560/e9c3970ab036de70892d86c6d221abfe/m/b/
so here i have override the model Image.php in my custom module and for specifically GIF image i have removed that md5 encryption code and call image path directly.
Below is the code :
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCatalogModelProductImage" type="ProductAjaxAnimationModelImage" />
</config>
image.php - overrided function setBaseFile.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
}
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
Hope it helps :)
add a comment |
So finally i got the solution for the same ,and resolved the issue
looking at the code i found that magento encoding image path in md5 string as well
if you have seen path on product detail page it is like - catalog/product/cache/image/700x560/e9c3970ab036de70892d86c6d221abfe/m/b/
so here i have override the model Image.php in my custom module and for specifically GIF image i have removed that md5 encryption code and call image path directly.
Below is the code :
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCatalogModelProductImage" type="ProductAjaxAnimationModelImage" />
</config>
image.php - overrided function setBaseFile.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
}
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
Hope it helps :)
So finally i got the solution for the same ,and resolved the issue
looking at the code i found that magento encoding image path in md5 string as well
if you have seen path on product detail page it is like - catalog/product/cache/image/700x560/e9c3970ab036de70892d86c6d221abfe/m/b/
so here i have override the model Image.php in my custom module and for specifically GIF image i have removed that md5 encryption code and call image path directly.
Below is the code :
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCatalogModelProductImage" type="ProductAjaxAnimationModelImage" />
</config>
image.php - overrided function setBaseFile.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
}
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
Hope it helps :)
answered Aug 22 '17 at 5:43
Manthan DaveManthan Dave
7,70421438
7,70421438
add a comment |
add a comment |
A correction here. If you use above script in image.php, GIF will start working no doubt, but i check is that after that user is not able to upload jpeg or png anymore. Below is that updated version of it with bug fix. I know its late, but hope it helps.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
}
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
add a comment |
A correction here. If you use above script in image.php, GIF will start working no doubt, but i check is that after that user is not able to upload jpeg or png anymore. Below is that updated version of it with bug fix. I know its late, but hope it helps.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
}
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
add a comment |
A correction here. If you use above script in image.php, GIF will start working no doubt, but i check is that after that user is not able to upload jpeg or png anymore. Below is that updated version of it with bug fix. I know its late, but hope it helps.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
}
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
A correction here. If you use above script in image.php, GIF will start working no doubt, but i check is that after that user is not able to upload jpeg or png anymore. Below is that updated version of it with bug fix. I know its late, but hope it helps.
public function setBaseFile($file)
{
$this->_isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
if ('/no_selection' == $file) {
$file = null;
}
if ($file) {
if (!$this->_fileExists($baseDir . $file) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->_isBaseFilePlaceholder = true;
// check if placeholder defined in config
$isConfigPlaceholder = $this->_scopeConfig->getValue(
"catalog/placeholder/{$this->getDestinationSubdir()}_placeholder",
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$configPlaceholder = '/placeholder/' . $isConfigPlaceholder;
if (!empty($isConfigPlaceholder) && $this->_fileExists($baseDir . $configPlaceholder)) {
$file = $configPlaceholder;
} else {
$this->_newFile = true;
return $this;
}
}
$baseFile = $baseDir . $file;
if (!$file || !$this->_mediaDirectory->isFile($baseFile)) {
throw new Exception(__('We can't find the image file.'));
}
$this->_baseFile = $baseFile;
$test_extension = substr($file,strpos($file, ".") + 1);
if($test_extension == "gif" || $test_extension == "GIF")
{
$path = $this->_catalogProductMediaConfig->getBaseMediaPath();
}
else
{
// build new filename (most important params)
$path = [
$this->_catalogProductMediaConfig->getBaseMediaPath(),
'cache',
$this->getDestinationSubdir(),
];
}
if (!empty($this->_width) || !empty($this->_height)) {
$path = "{$this->_width}x{$this->_height}";
}
// add misk params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams = $this->getWatermarkFile();
$miscParams = $this->getWatermarkImageOpacity();
$miscParams = $this->getWatermarkPosition();
$miscParams = $this->getWatermarkWidth();
$miscParams = $this->getWatermarkHeight();
}
$path = md5(implode('_', $miscParams));
// append prepared filename
$this->_newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
answered 19 mins ago
JohnJohn
385211
385211
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f189888%2fmagento-2-gif-images-animation-is-not-working-on-frontend%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check this one may be help to you : magento.stackexchange.com/questions/189531/…
– Suresh Chikani
Aug 21 '17 at 8:49
@SHPatel Thanks , i have already checked that , but needed better solution for this
– Manthan Dave
Aug 21 '17 at 8:50