cancel
Showing results for 
Search instead for 
Did you mean: 

Allow SVG Upload on Category Thumbnail

Allow SVG Upload on Category Thumbnail

Hello Members,

 

I try to implement that the category image and thumbnail allow SVG. I found in app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php on Line 60 

  $uploader->addValidateCallback(
                Mage_Core_Model_File_Validator_Image::NAME,
                new Mage_Core_Model_File_Validator_Image(),
                "validate"
            );

That this method is responsible to check the Image files. This method is implemented in  the app/code/core/Mage/Core/Model/File/Validator/Image.php

 /**
     * Validation callback for checking is file is image
     *
     * @param  string $filePath Path to temporary uploaded file
     * @return null
     * @throws Mage_Core_Exception
     */
    public function validate($filePath)
    {
        $fileInfo = getimagesize($filePath);
        if (is_array($fileInfo) and isset($fileInfo[2])) {
            if ($this->isImageType($fileInfo[2])) {
                return null;
            }
        }
        throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid MIME type.'));
    }

    /**
     * Returns is image by image type
     * @param int $nImageType
     * @return bool
     */
    protected function isImageType($nImageType)
    {
        return in_array($nImageType, $this->_allowedImageTypes);
    }

and check the

protected $_allowedImageTypes = array(
        IMAGETYPE_JPEG,
        IMAGETYPE_GIF,
        IMAGETYPE_JPEG2000,
        IMAGETYPE_PNG,
        IMAGETYPE_ICO,
        IMAGETYPE_TIFF_II,
        IMAGETYPE_TIFF_MM
    );

 What is here the best solution ? I thought about to extend this method and build an another "allowedArray" with SVG for example. 

Import is here I need this for the categories not the products image uploader. 

 

Thank you! Best regards, timmeyy

2 REPLIES 2

Re: Allow SVG Upload on Category Thumbnail

Hi,

 

If you want to not disturb your core module then you have to create custom module under app\code\local and extend that class and modify the method accordingly.

 

I think this is the best solution. If you want to more information then please let me know.

 

Thanks,

Dibyajyoti

Re: Allow SVG Upload on Category Thumbnail

Hello,

 

thank you for your response.

Thats the plan. I will build my on extension, but maybe it exists a better solution.

I have no idea whats the best logic to check if the file svg or not.

 

Thank you! Best regards, timmeyy