Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimize] Add config for admin choose way for generate image of thumbnail for JImage class #7857

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions administrator/components/com_config/model/form/application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,23 @@
size="40" />
</fieldset>

<fieldset
name="thumbnail"
label="CONFIG_THUMBNAIL_SETTINGS_LABEL">
<field
name="thumbnail_generate_method"
type="radio"
class="btn-group"
label="COM_CONFIG_FIELD_THUMBNAIL_GENERATE_METHOD_LABEL"
description="COM_CONFIG_FIELD_THUMBNAIL_GENERATE_METHOD_DESC"
required="false"
default="1">
<option value="1">COM_CONFIG_FIELD_VALUE_THUMBNAIL_QUALITY</option>
<option value="0">COM_CONFIG_FIELD_VALUE_THUMBNAIL_SPEED</option>

</field>
</fieldset>

<fieldset
name="permissions"
label="CONFIG_PERMISSION_SETTINGS_LABEL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<div class="span6">
<?php echo $this->loadTemplate('seo'); ?>
<?php echo $this->loadTemplate('cookie'); ?>
<?php echo $this->loadTemplate('thumbnail'); ?>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_config
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

$this->name = JText::_('COM_CONFIG_THUMBNAIL_SETTINGS');
$this->fieldsname = 'thumbnail';
echo JLayoutHelper::render('joomla.content.options_default', $this);
5 changes: 5 additions & 0 deletions administrator/language/en-GB/en-GB.com_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ COM_CONFIG_COMPONENT_FIELDSET_LABEL="Component"
COM_CONFIG_COOKIE_SETTINGS="Cookie Settings"
COM_CONFIG_DATABASE_SETTINGS="Database Settings"
COM_CONFIG_DEBUG_SETTINGS="Debug Settings"
COM_CONFIG_THUMBNAIL_SETTINGS="Image Thumbnail Settings"
COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE="The cache folder is not writable: %s"
COM_CONFIG_ERROR_COMPONENT_ASSET_NOT_FOUND="The asset for the component could not be found. Permissions have not been saved."
COM_CONFIG_ERROR_CONFIG_EXTENSION_NOT_FOUND="The Global Configuration extension could not be found. Text filter settings have not been saved."
Expand Down Expand Up @@ -188,6 +189,8 @@ COM_CONFIG_FIELD_SITENAME_PAGETITLES_DESC="Begin or end all Page Titles with the
COM_CONFIG_FIELD_SITENAME_PAGETITLES_LABEL="Include Site Name in Page Titles"
COM_CONFIG_FIELD_TEMP_PATH_DESC="Please select a writable Temp folder."
COM_CONFIG_FIELD_TEMP_PATH_LABEL="Path to Temp Folder"
COM_CONFIG_FIELD_THUMBNAIL_GENERATE_METHOD_LABEL="Thumbnail generate method"
COM_CONFIG_FIELD_THUMBNAIL_GENERATE_METHOD_DESC="Choose between 2 way for generate image thumbnail. Best quality or fastest speed."
COM_CONFIG_FIELD_UNICODESLUGS_DESC="Choose between transliteration and unicode aliases. Transliteration is default."
COM_CONFIG_FIELD_UNICODESLUGS_LABEL="Unicode Aliases"
COM_CONFIG_FIELD_VALUE_ADMINISTRATOR_ONLY="Administrator Only"
Expand All @@ -211,6 +214,8 @@ COM_CONFIG_FIELD_VALUE_SITE_EMAIL="Site Email"
COM_CONFIG_FIELD_VALUE_SMTP="SMTP"
COM_CONFIG_FIELD_VALUE_SSL="SSL"
COM_CONFIG_FIELD_VALUE_SYSTEM_DEFAULT="System Default"
COM_CONFIG_FIELD_VALUE_THUMBNAIL_QUALITY="Best quality"
COM_CONFIG_FIELD_VALUE_THUMBNAIL_SPEED="Fastest"
COM_CONFIG_FIELD_VALUE_TLS="TLS"
COM_CONFIG_FTP_DETAILS="FTP Login Details"
COM_CONFIG_FTP_DETAILS_TIP="For updating your configuration.php file, Joomla will most likely need your FTP account details. Please enter them in the form fields below."
Expand Down
25 changes: 21 additions & 4 deletions libraries/joomla/image/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ class JImage
*/
protected static $formats = array();

/**
* @var string Method when generate thumbnail image.
*
* @since 3.4.4
*/
protected $generateBestQuality = true;

/**
* Class constructor.
*
Expand Down Expand Up @@ -127,6 +134,10 @@ public function __construct($source = null)
// If the source input is not empty, assume it is a path and populate the image handle.
$this->loadFile($source);
}

// Get generate method from global configuration
$config = JFactory::getConfig();
$this->generateBestQuality = (boolean) $config->get('thumbnail_generate_method', true);
}

/**
Expand Down Expand Up @@ -420,12 +431,15 @@ public function crop($width, $height, $left = null, $top = null, $createNew = tr
// Set the transparent color values for the new image.
imagecolortransparent($handle, $color);
imagefill($handle, 0, 0, $color);
}

imagecopyresized($handle, $this->handle, 0, 0, $left, $top, $width, $height, $width, $height);
if ($this->generateBestQuality)
{
imagecopyresampled($handle, $this->handle, 0, 0, $left, $top, $width, $height, $width, $height);
}
else
{
imagecopyresampled($handle, $this->handle, 0, 0, $left, $top, $width, $height, $width, $height);
imagecopyresized($handle, $this->handle, 0, 0, $left, $top, $width, $height, $width, $height);
}

// If we are cropping to a new image, create a new JImage object.
Expand Down Expand Up @@ -758,8 +772,11 @@ public function resize($width, $height, $createNew = true, $scaleMethod = self::
// Set the transparent color values for the new image.
imagecolortransparent($handle, $color);
imagefill($handle, 0, 0, $color);
}

imagecopyresized(
if ($this->generateBestQuality)
{
imagecopyresampled(
$handle,
$this->handle,
$offset->x,
Expand All @@ -774,7 +791,7 @@ public function resize($width, $height, $createNew = true, $scaleMethod = self::
}
else
{
imagecopyresampled(
imagecopyresized(
$handle,
$this->handle,
$offset->x,
Expand Down