Explorar o código

#123 - logo resizing with transparency & retina support

Alex Trofimov %!s(int64=11) %!d(string=hai) anos
pai
achega
3b88d3d49b

+ 1 - 0
inc/classes/BxDolImageResize.php

@@ -521,6 +521,7 @@ class BxDolImageResize extends BxDol implements iBxDolSingleton
                 if (!isset($this->gdInfoArray['PNG Support']) || !$this->gdInfoArray['PNG Support'])
                     return ($iErr = IMAGE_ERROR_GD_TYPE_NOT_SUPPORTED);
                 $r = imagecreatefrompng( $s );
+                imagesavealpha($r, true);
                 return $r;
             default:
                 return ($iErr = IMAGE_ERROR_WRONG_TYPE);

+ 2 - 0
install/sql/system.sql

@@ -227,6 +227,8 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_site_logo', '', '0', 'digit', '', '', '', 20),
 (@iCategoryId, 'sys_site_logo_alt', '_adm_dsg_txt_alt_text', '0', 'text', '', '', '', 21),
 (@iCategoryId, 'sys_site_icon', '', '0', 'digit', '', '', '', 22),
+(@iCategoryId, 'sys_site_logo_width', '_adm_stg_cpt_option_sys_site_logo_width', '240', 'digit', '', '', '', 23),
+(@iCategoryId, 'sys_site_logo_height', '_adm_stg_cpt_option_sys_site_logo_height', '44', 'digit', '', '', '', 24),
 (@iCategoryId, 'main_div_width', '', '1000px', 'digit', '', '', '', 25),
 
 (@iCategoryId, 'sys_template_cache_image_enable', '', '', 'checkbox', '', '', '', 30),

+ 2 - 0
modules/boonex/english/data/langs/system.xml

@@ -1148,6 +1148,8 @@
 	<string name="_adm_stg_cpt_option_sys_security_form_token_lifetime"><![CDATA[CSRF token lifetime in seconds(0 - do not track time)]]></string>
 	<string name="_adm_stg_cpt_option_sys_security_impact_threshold_block"><![CDATA[Total security impact threshold to send report and block aggressor]]></string>
 	<string name="_adm_stg_cpt_option_sys_security_impact_threshold_log"><![CDATA[Total security impact threshold to send report]]></string>
+	<string name="_adm_stg_cpt_option_sys_site_logo_height"><![CDATA[Logo Height]]></string>
+	<string name="_adm_stg_cpt_option_sys_site_logo_width"><![CDATA[Logo Width]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_default"><![CDATA[Default storage engine (other than Local may require custom/additional setup)]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_s3_access_key"><![CDATA[AWS access key]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_s3_bucket"><![CDATA[AWS bucket]]></string>

+ 5 - 2
studio/classes/BxDolStudioDesigner.php

@@ -80,7 +80,8 @@ class BxDolStudioDesigner extends BxTemplStudioPage
 
         if(!empty($_FILES['image']['tmp_name'])) {
             bx_import('BxDolStorage');
-            $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
+
+            $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
 
             if(!$this->deleteLogo())
                 return $this->getJsResult('_adm_dsg_err_remove_old_logo');
@@ -96,6 +97,8 @@ class BxDolStudioDesigner extends BxTemplStudioPage
         }
 
         $this->oDb->setParam('sys_site_logo_alt', $oForm->getCleanValue('alt'));
+        $this->oDb->setParam('sys_site_logo_width', $oForm->getCleanValue('width'));
+        $this->oDb->setParam('sys_site_logo_height', $oForm->getCleanValue('height'));
         return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_LOGO);
     }
 
@@ -104,7 +107,7 @@ class BxDolStudioDesigner extends BxTemplStudioPage
         $iProfileId = getLoggedId();
 
         bx_import('BxDolStorage');
-        $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
+        $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
 
         $iId = (int)getParam('sys_site_logo');
         if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))

+ 24 - 4
studio/template/scripts/BxBaseStudioDesigner.php

@@ -125,8 +125,6 @@ class BxBaseStudioDesigner extends BxDolStudioDesigner
     {
         $oTemplate = BxDolStudioTemplate::getInstance();
 
-        $sAlt = getParam('sys_site_logo_alt');
-
         $aForm = array(
             'form_attrs' => array(
                 'id' => $this->sLogoFormId,
@@ -157,14 +155,36 @@ class BxBaseStudioDesigner extends BxDolStudioDesigner
                     'caption' => _t('_adm_dsg_txt_upload_image'),
                     'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
                     'ajax_action_delete' => $this->getPageJsObject() . '.deleteLogo()',
-                    'value' => (int)getParam('sys_site_logo')
+                    'storage_object' => 'sys_images_custom',
+                    'transcoder_object' => 'sys_custom_images',
+                    'transcoder_image_width' => getParam('sys_site_logo_width'),
+                    'transcoder_image_height' => getParam('sys_site_logo_height'),
+                    'value' => (int)getParam('sys_site_logo'),
+                ),
+                'width' => array(
+                    'type' => 'text',
+                    'name' => 'width',
+                    'caption' => _t('_adm_stg_cpt_option_sys_site_logo_width'),
+                    'value' => getParam('sys_site_logo_width'),
+                    'db' => array (
+                        'pass' => 'Int',
+                    ),
+                ),
+                'height' => array(
+                    'type' => 'text',
+                    'name' => 'height',
+                    'caption' => _t('_adm_stg_cpt_option_sys_site_logo_height'),
+                    'value' => getParam('sys_site_logo_height'),
+                    'db' => array (
+                        'pass' => 'Int',
+                    ),
                 ),
                 'alt' => array(
                     'type' => 'text',
                     'name' => 'alt',
                     'caption' => _t('_adm_dsg_txt_alt_text'),
                     'info' => _t('_adm_dsg_dsc_alt_text'),
-                    'value' => $sAlt,
+                    'value' => getParam('sys_site_logo_alt'),
                     'checker' => array(
                         'func' => '',
                         'params' => array(),

+ 17 - 4
studio/template/scripts/BxBaseStudioFormView.php

@@ -75,11 +75,24 @@ class BxBaseStudioFormView extends BxDolStudioForm
         );
 
         if(($iId = (int)$aInput['value']) != 0) {
-            bx_import('BxDolStorage');
-            $sStorage = isset($aInput['storage_object']) && $aInput['storage_object'] != '' ? $aInput['storage_object'] : BX_DOL_STORAGE_OBJ_IMAGES;
-            $oStorage = BxDolStorage::getObjectInstance($sStorage);
 
-            $sFileUrl = $oStorage->getFileUrlById($iId);
+            $sFileUrl = false;
+            if (!empty($aInput['transcoder_object'])) {
+                bx_import('BxDolTranscoderImage');
+                $oTranscoder = BxDolTranscoderImage::getObjectInstance($aInput['transcoder_object']);
+                $sFileUrl = $oTranscoder->getFileUrlNotReady($iId);
+                if (isset($aInput['transcoder_image_width']) && $aInput['transcoder_image_width'] > 0)
+                    $sFileUrl = bx_append_url_params($sFileUrl, array('x' => $aInput['transcoder_image_width']));
+                if (isset($aInput['transcoder_image_height']) && $aInput['transcoder_image_height'] > 0)
+                    $sFileUrl = bx_append_url_params($sFileUrl, array('y' => $aInput['transcoder_image_height']));
+            } 
+            else {
+                bx_import('BxDolStorage');
+                $sStorage = isset($aInput['storage_object']) && $aInput['storage_object'] != '' ? $aInput['storage_object'] : BX_DOL_STORAGE_OBJ_IMAGES;
+                $oStorage = BxDolStorage::getObjectInstance($sStorage);
+                $sFileUrl = $oStorage->getFileUrlById($iId);
+            }
+
             if($sFileUrl !== false) {
                 $aTmplVarsPreview['bx_if:show_empty']['condition'] = false;
                 $aTmplVarsPreview['bx_if:show_image'] = array(

+ 26 - 8
template/scripts/BxBaseFunctions.php

@@ -274,6 +274,30 @@ class BxBaseFunctions extends BxDol implements iBxDolSingleton
         return $sCode;
     }
 
+    /**
+     * Get logo URL.
+     * @return string
+     */
+    function getMainLogoUrl()
+    {
+        $iFileId = (int)getParam('sys_site_logo');
+        if (!$iFileId) 
+            return false;
+
+        bx_import('BxDolTranscoder');
+        $oStorage = BxDolTranscoder::getObjectInstance('sys_custom_images');
+        $sFileUrl = $oStorage->getFileUrl($iFileId);
+        if (!$sFileUrl) 
+            return false;
+
+        if (getParam('sys_site_logo_width') > 0)
+            $sFileUrl = bx_append_url_params($sFileUrl, array('x' => getParam('sys_site_logo_width')));
+        if (getParam('sys_site_logo_height') > 0)
+            $sFileUrl = bx_append_url_params($sFileUrl, array('y' => getParam('sys_site_logo_height')));
+
+        return $sFileUrl;
+    }
+
     /**
      * Get logo HTML.
      * @return string
@@ -285,14 +309,8 @@ class BxBaseFunctions extends BxDol implements iBxDolSingleton
         $sAlt = getParam('sys_site_logo_alt') ? getParam('sys_site_logo_alt') : getParam('site_title');
         $sLogo = $sAlt;
 
-        $iFileId = (int)getParam('sys_site_logo');
-        if ($iFileId) {
-            bx_import('BxDolStorage');
-            $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
-            $sFileUrl = $oStorage->getFileUrlById($iFileId);
-            if ($sFileUrl)
-                $sLogo = '<img src="' . $sFileUrl . '" id="bx-logo" class="bx-def-margin-sec" alt="' . bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE) . '" />';
-        }
+        if ($sFileUrl = $this->getMainLogoUrl())
+            $sLogo = '<img src="' . $sFileUrl . '" id="bx-logo" class="bx-def-margin-sec" alt="' . bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE) . '" />';
 
         return '<a class="bx-def-font-contrasted" href="' . BX_DOL_URL_ROOT . '" title="' . bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE) . '">' . $sLogo . '</a>';
     }