first commit
This commit is contained in:
12
modules/gmcrop/config_pl.xml
Normal file
12
modules/gmcrop/config_pl.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>gmcrop</name>
|
||||
<displayName><![CDATA[Perfect Thumbnails]]></displayName>
|
||||
<version><![CDATA[1.2.3]]></version>
|
||||
<description><![CDATA[Kadruj obrazy zamiast dodawać białą przestrzeń wokół nich]]></description>
|
||||
<author><![CDATA[GreenMouseStudio.com]]></author>
|
||||
<tab><![CDATA[administration]]></tab>
|
||||
<is_configurable>1</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
311
modules/gmcrop/gmcrop.php
Normal file
311
modules/gmcrop/gmcrop.php
Normal file
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
/**
|
||||
* Crop images instead of adding whitespace around them
|
||||
*
|
||||
* @package gmcrop
|
||||
* @author Dariusz Tryba (contact@greenmousestudio.com)
|
||||
* @copyright Copyright (c) Green Mouse Studio (http://www.greenmousestudio.com)
|
||||
* @license http://greenmousestudio.com/paid-license.txt
|
||||
*/
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Gmcrop extends Module
|
||||
{
|
||||
protected $cropOrigin;
|
||||
protected $croppedImageTypes = array();
|
||||
protected $backgroundColor;
|
||||
protected $cropBackground = false;
|
||||
protected $optimizeForBandwitdh = false;
|
||||
protected $fittedImageTypes = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'gmcrop';
|
||||
$this->prefix = strtoupper($this->name);
|
||||
$this->tab = 'administration';
|
||||
$this->version = '1.2.3';
|
||||
$this->author = 'GreenMouseStudio.com';
|
||||
$this->need_instance = 0;
|
||||
$this->bootstrap = true;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Perfect Thumbnails');
|
||||
$this->description = $this->l('Crop images instead of adding whitespace around them');
|
||||
|
||||
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
|
||||
$this->getConfiguration();
|
||||
}
|
||||
|
||||
protected function getConfiguration()
|
||||
{
|
||||
$this->cropOrigin = Configuration::get($this->prefix.'_ORIGIN');
|
||||
$this->backgroundColor = Configuration::get($this->prefix.'_BGCOLOR');
|
||||
$imageTypesString = Configuration::get($this->prefix.'_CROPPEDTYPES');
|
||||
$this->croppedImageTypes = explode(',', $imageTypesString);
|
||||
$this->cropBackground = (bool)Configuration::get($this->prefix.'_CROPBG');
|
||||
$this->optimizeForBandwitdh = (bool)Configuration::get($this->prefix.'_BANDWIDTH');
|
||||
$optimizedTypesString = Configuration::get($this->prefix.'_FITTEDTYPES');
|
||||
$this->fittedImageTypes = explode(',', $optimizedTypesString);
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
return parent::install() &&
|
||||
Configuration::updateValue($this->prefix.'_ORIGIN', 4) &&
|
||||
Configuration::updateValue($this->prefix.'_BGCOLOR', '#ffffff') &&
|
||||
Configuration::updateValue($this->prefix.'_CROPPEDTYPES', 'home_default') &&
|
||||
Configuration::updateValue($this->prefix.'_CROPBG', true) &&
|
||||
Configuration::updateValue($this->prefix.'_FITTEDTYPES', 'thickbox_default') &&
|
||||
$this->registerHook('displayBackOfficeHeader');
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
Configuration::deleteByName($this->prefix.'_ORIGIN');
|
||||
Configuration::deleteByName($this->prefix.'_BGCOLOR');
|
||||
Configuration::deleteByName($this->prefix.'_CROPPEDTYPES');
|
||||
Configuration::deleteByName($this->prefix.'_FITTEDTYPES');
|
||||
Configuration::deleteByName($this->prefix.'_CROPBG');
|
||||
return parent::uninstall();
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
$this->getConfiguration();
|
||||
$output = '';
|
||||
if (((bool) Tools::isSubmit($this->name.'submit')) == true) {
|
||||
$this->postProcess();
|
||||
$output .= $this->displayConfirmation($this->l('Settings updated'));
|
||||
}
|
||||
$output .= $this->renderForm();
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function getImagesTypes()
|
||||
{
|
||||
$data = array();
|
||||
$imagesTypes = ImageType::getImagesTypes();
|
||||
foreach ($imagesTypes as $type) {
|
||||
$data[] = $type['name'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function renderTypesCheckboxes($name, $label, $selectedTypes)
|
||||
{
|
||||
$content = '<div class="form-group media-body">
|
||||
<label class="control-label col-lg-3">'.$label.'</label>
|
||||
<div class="col-lg-9">';
|
||||
$imageTypes = $this->getImagesTypes();
|
||||
foreach ($imageTypes as $type) {
|
||||
$content .= '<div class="checkbox">';
|
||||
$content .= '<label for="img_'.$name.$type.'">';
|
||||
$content .= '<input id="img_'.$name.$type.'" type="checkbox" name="'.$name.'[]" value="'.$type.'" ';
|
||||
if (is_array($selectedTypes) && in_array($type, $selectedTypes)) {
|
||||
$content .= ' checked ';
|
||||
}
|
||||
$content.= '>';
|
||||
$content .= $type.'</label>';
|
||||
$content .= '</div>';
|
||||
}
|
||||
$content .= '</div></div>';
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function renderPanelFooter()
|
||||
{
|
||||
$output = '<div class="panel-footer">
|
||||
<button type="submit" value="1" id="module_form_submit_btn" name="'.$this->name.'submit" class="btn btn-default pull-right">
|
||||
<i class="process-icon-save"></i>'.$this->l('Save').'
|
||||
</button></div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function renderForm()
|
||||
{
|
||||
$output = '<div class="panel">'
|
||||
.'<div class="panel-heading"><i class="icon-cogs"></i> '
|
||||
.$this->l('Settings')
|
||||
.'</div>'
|
||||
.'<form action="" method="post">'
|
||||
.'<div class="form-wrapper">';
|
||||
if (function_exists('imagecropauto')) {
|
||||
$output .= $this->renderCheckbox($this->prefix.'_CROPBG', $this->l('Extract product from background'), $this->cropBackground, $this->l('Removes white or transparent background around the product on the original image.'));
|
||||
}
|
||||
$output .= $this->renderTypesCheckboxes('GMCROP_FITTEDTYPES', $this->l('Keep original proportions for images of type:'), $this->fittedImageTypes);
|
||||
$output .= $this->renderOriginMatrix();
|
||||
$output .= $this->renderTypesCheckboxes('GMCROP_CROPPEDTYPES', $this->l('Crop images of type:'), $this->croppedImageTypes);
|
||||
$output .= $this->renderColorPicker();
|
||||
$output .= $this->renderPanelFooter();
|
||||
$output .= '</form></div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function renderOriginMatrix()
|
||||
{
|
||||
$output = '<div class="form-group media-body">
|
||||
<label class="control-label col-lg-3">'.$this->l('Cropping origin').'</label><div class="col-lg-9">';
|
||||
$output .= '<table><tr>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="0" ';
|
||||
if ($this->cropOrigin == 0) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="1" ';
|
||||
if ($this->cropOrigin == 1) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="2" ';
|
||||
if ($this->cropOrigin == 2) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '</tr>';
|
||||
$output .= '<tr>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="3" ';
|
||||
if ($this->cropOrigin == 3) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="4" ';
|
||||
if ($this->cropOrigin == 4) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="5" ';
|
||||
if ($this->cropOrigin == 5) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '</tr>';
|
||||
$output .= '<tr>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="6" ';
|
||||
if ($this->cropOrigin == 6) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="7" ';
|
||||
if ($this->cropOrigin == 7) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '<td style="padding:5px"><input type="radio" name="GMCROP_ORIGIN" value="8" ';
|
||||
if ($this->cropOrigin == 8) {
|
||||
$output .= ' checked="checked" ';
|
||||
}
|
||||
$output .= '/></td>';
|
||||
$output .= '</tr>';
|
||||
$output .= '</table>';
|
||||
$output .= '</div></div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function renderTextInput($name, $label, $value = null, $help = null)
|
||||
{
|
||||
$content = '<div class="form-group media-body">
|
||||
<label class="control-label col-lg-3">'.$label.'</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="text" name="'.$name.'" id="'.$name.'" value="'.$value.'" class="">';
|
||||
if ($help != null) {
|
||||
$content .= '<p class="help-block">'.$help.'</p>';
|
||||
}
|
||||
$content .= '</div>
|
||||
</div>';
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function renderCheckbox($name, $label, $checked = false, $help = null, $onText = null,
|
||||
$offText = null)
|
||||
{
|
||||
if (!$onText) {
|
||||
$onText = $this->l('Yes');
|
||||
}
|
||||
if (!$offText) {
|
||||
$offText = $this->l('No');
|
||||
}
|
||||
$content = '<div class="form-group media-body">
|
||||
<label class="control-label col-lg-3">'.$label.'</label>
|
||||
<div class="col-lg-9">
|
||||
<span class="switch prestashop-switch fixed-width-lg">
|
||||
<input type="radio" name="'.$name.'" id="'.$name.'_on" value="1" ';
|
||||
if ($checked) {
|
||||
$content .= ' checked="checked" ';
|
||||
}
|
||||
$content .= '>
|
||||
<label for="'.$name.'_on">'.$onText.'</label>
|
||||
<input type="radio" name="'.$name.'" id="'.$name.'_off" value="" ';
|
||||
if (!$checked) {
|
||||
$content .= ' checked="checked" ';
|
||||
}
|
||||
$content .= '">
|
||||
<label for="'.$name.'_off">'.$offText.'</label>
|
||||
<a class="slide-button btn"></a>
|
||||
</span>';
|
||||
if ($help != null) {
|
||||
$content .= '<p class="help-block">'.$help.'</p>';
|
||||
}
|
||||
|
||||
$content .='</div>
|
||||
</div>';
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function renderColorPicker()
|
||||
{
|
||||
$content = '';
|
||||
$content .= '<div class="form-group media-body">
|
||||
<label class="control-label col-lg-3">'.$this->l('Background color').'</label>
|
||||
<div class="col-lg-9 ">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-2">
|
||||
<div class="row">
|
||||
<div class="input-group">
|
||||
<input type="color" data-hex="true" name="'.$this->prefix.'_BGCOLOR" value="'.$this->backgroundColor.'"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function postProcess()
|
||||
{
|
||||
$this->cropOrigin = Tools::getValue($this->prefix.'_ORIGIN');
|
||||
$this->backgroundColor = Tools::getValue($this->prefix.'_BGCOLOR');
|
||||
$this->croppedImageTypes = Tools::getValue($this->prefix.'_CROPPEDTYPES');
|
||||
$this->cropBackground = Tools::getValue($this->prefix.'_CROPBG');
|
||||
$this->optimizeForBandwitdh = Tools::getValue($this->prefix.'_BANDWIDTH');
|
||||
$this->fittedImageTypes = Tools::getValue($this->prefix.'_FITTEDTYPES');
|
||||
$this->updateConfiguration();
|
||||
}
|
||||
|
||||
protected function updateConfiguration()
|
||||
{
|
||||
Configuration::updateValue($this->prefix.'_ORIGIN', $this->cropOrigin);
|
||||
Configuration::updateValue($this->prefix.'_BGCOLOR', $this->backgroundColor);
|
||||
$croppedTypesString = '';
|
||||
if (is_array($this->croppedImageTypes)) {
|
||||
$croppedTypesString = implode(',', $this->croppedImageTypes);
|
||||
}
|
||||
Configuration::updateValue($this->prefix.'_CROPPEDTYPES', $croppedTypesString);
|
||||
Configuration::updateValue($this->prefix.'_CROPBG', $this->cropBackground);
|
||||
$fittedTypesString = '';
|
||||
if (is_array($this->fittedImageTypes)) {
|
||||
$fittedTypesString = implode(',', $this->fittedImageTypes);
|
||||
}
|
||||
Configuration::updateValue($this->prefix.'_FITTEDTYPES', $fittedTypesString);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hookDisplayBackOfficeHeader()
|
||||
{
|
||||
$this->context->controller->addJquery();
|
||||
$this->context->controller->addjqueryPlugin('colorpicker');
|
||||
}
|
||||
}
|
||||
35
modules/gmcrop/index.php
Normal file
35
modules/gmcrop/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2015 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
BIN
modules/gmcrop/logo.png
Normal file
BIN
modules/gmcrop/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
321
modules/gmcrop/override/classes/ImageManager.php
Normal file
321
modules/gmcrop/override/classes/ImageManager.php
Normal file
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
/*
|
||||
* @package gmcrop
|
||||
* @author Dariusz Tryba (contact@greenmousestudio.com)
|
||||
* @copyright Copyright (c) Green Mouse Studio (http://www.greenmousestudio.com)
|
||||
* @license http://greenmousestudio.com/paid-license.txt
|
||||
*/
|
||||
|
||||
class ImageManager extends ImageManagerCore
|
||||
{
|
||||
|
||||
public static function resize($sourceFile, $destinationFile, $destinationWidth = null, $destinationHeight = null,
|
||||
$fileType = 'jpg', $forceType = false, &$error = 0, &$targetWidth = null,
|
||||
&$targetHeight = null, $quality = 5, &$sourceWidth = null, &$sourceHeight = null)
|
||||
{
|
||||
clearstatcache(true, $sourceFile);
|
||||
|
||||
if (!file_exists($sourceFile) || !filesize($sourceFile)) {
|
||||
return !($error = self::ERROR_FILE_NOT_EXIST);
|
||||
}
|
||||
|
||||
list($tmpWidth, $tmpHeight, $type) = getimagesize($sourceFile);
|
||||
|
||||
$rotate = 0;
|
||||
if (function_exists('exif_read_data') && function_exists('mb_strtolower')) {
|
||||
$exif = @exif_read_data($sourceFile);
|
||||
|
||||
if ($exif && isset($exif['Orientation'])) {
|
||||
switch ($exif['Orientation']) {
|
||||
case 3:
|
||||
$sourceWidth = $tmpWidth;
|
||||
$sourceHeight = $tmpHeight;
|
||||
$rotate = 180;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$sourceWidth = $tmpHeight;
|
||||
$sourceHeight = $tmpWidth;
|
||||
$rotate = -90;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$sourceWidth = $tmpHeight;
|
||||
$sourceHeight = $tmpWidth;
|
||||
$rotate = 90;
|
||||
break;
|
||||
|
||||
default:
|
||||
$sourceWidth = $tmpWidth;
|
||||
$sourceHeight = $tmpHeight;
|
||||
}
|
||||
} else {
|
||||
$sourceWidth = $tmpWidth;
|
||||
$sourceHeight = $tmpHeight;
|
||||
}
|
||||
} else {
|
||||
$sourceWidth = $tmpWidth;
|
||||
$sourceHeight = $tmpHeight;
|
||||
}
|
||||
|
||||
//create image first
|
||||
$srcImage = ImageManager::create($type, $sourceFile);
|
||||
|
||||
if (Module::isEnabled('gmcrop')) {
|
||||
if (function_exists('imagecropauto')) {
|
||||
//autocrop
|
||||
if (Configuration::get('GMCROP_CROPBG')) {
|
||||
//attempt to crop the transparent background
|
||||
$cropped = imagecropauto($srcImage, IMG_CROP_THRESHOLD, 0.25, 16777215);
|
||||
if ($cropped !== false) {
|
||||
imagedestroy($srcImage);
|
||||
$srcImage = $cropped;
|
||||
//get new size after autocrop
|
||||
$sourceWidth = imagesx($srcImage);
|
||||
$sourceHeight = imagesy($srcImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
//keep proportions mode
|
||||
$keepProportions = false;
|
||||
$fittedImageTypes = explode(',', Configuration::get('GMCROP_FITTEDTYPES'));
|
||||
if (is_array($fittedImageTypes) && (count($fittedImageTypes) > 0)) {
|
||||
foreach ($fittedImageTypes as $fittedImageType) {
|
||||
if (strlen($fittedImageType) > 1) {
|
||||
if (strpos($destinationFile, $fittedImageType) !== false) {
|
||||
$keepProportions = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($keepProportions) {
|
||||
$widthRatio = $destinationWidth / $sourceWidth;
|
||||
$heightRatio = $destinationHeight / $sourceHeight;
|
||||
if (($widthRatio < 1) || ($heightRatio < 1)) {
|
||||
if ($widthRatio < $heightRatio) {
|
||||
$destinationWidth = $sourceWidth * $widthRatio;
|
||||
$destinationHeight = $sourceHeight * $widthRatio;
|
||||
} else {
|
||||
$destinationWidth = $sourceWidth * $heightRatio;
|
||||
$destinationHeight = $sourceHeight * $heightRatio;
|
||||
}
|
||||
} else {
|
||||
$destinationWidth = $sourceWidth;
|
||||
$destinationHeight = $sourceHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If PS_IMAGE_QUALITY is activated, the generated image will be a PNG with .jpg as a file extension.
|
||||
// This allow for higher quality and for transparency. JPG source files will also benefit from a higher quality
|
||||
// because JPG reencoding by GD, even with max quality setting, degrades the image.
|
||||
if (Configuration::get('PS_IMAGE_QUALITY') == 'png_all' || (Configuration::get('PS_IMAGE_QUALITY') == 'png' && $type
|
||||
== IMAGETYPE_PNG) && !$forceType) {
|
||||
$fileType = 'png';
|
||||
}
|
||||
|
||||
if (!$sourceWidth) {
|
||||
return !($error = self::ERROR_FILE_WIDTH);
|
||||
}
|
||||
if (!$destinationWidth) {
|
||||
$destinationWidth = $sourceWidth;
|
||||
}
|
||||
if (!$destinationHeight) {
|
||||
$destinationHeight = $sourceHeight;
|
||||
}
|
||||
|
||||
$widthDiff = $destinationWidth / $sourceWidth;
|
||||
$heightDiff = $destinationHeight / $sourceHeight;
|
||||
|
||||
$rgb = ImageManager::hex2rgb(Configuration::get('GMCROP_BGCOLOR'));
|
||||
$red = $rgb[0];
|
||||
$green = $rgb[1];
|
||||
$blue = $rgb[2];
|
||||
|
||||
$crop = false;
|
||||
if (Module::isEnabled('gmcrop')) {
|
||||
$croppedImageTypes = explode(',', Configuration::get('GMCROP_CROPPEDTYPES'));
|
||||
if (is_array($croppedImageTypes) && (count($croppedImageTypes) > 0)) {
|
||||
foreach ($croppedImageTypes as $croppedImageType) {
|
||||
if (strlen($croppedImageType) > 1) {
|
||||
if (strpos($destinationFile, $croppedImageType) !== false) {
|
||||
$crop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$red = $green = $blue = 255;
|
||||
}
|
||||
if (!$crop) {
|
||||
$psImageGenerationMethod = Configuration::get('PS_IMAGE_GENERATION_METHOD');
|
||||
if ($widthDiff > 1 && $heightDiff > 1) {
|
||||
$nextWidth = $sourceWidth;
|
||||
$nextHeight = $sourceHeight;
|
||||
} else {
|
||||
if ($psImageGenerationMethod == 2 || (!$psImageGenerationMethod && $widthDiff > $heightDiff)) {
|
||||
$nextHeight = $destinationHeight;
|
||||
$nextWidth = round(($sourceWidth * $nextHeight) / $sourceHeight);
|
||||
$destinationWidth = (int) (!$psImageGenerationMethod ? $destinationWidth : $nextWidth);
|
||||
} else {
|
||||
$nextWidth = $destinationWidth;
|
||||
$nextHeight = round($sourceHeight * $destinationWidth / $sourceWidth);
|
||||
$destinationHeight = (int) (!$psImageGenerationMethod ? $destinationHeight : $nextHeight);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ImageManager::checkImageMemoryLimit($sourceFile)) {
|
||||
return !($error = self::ERROR_MEMORY_LIMIT);
|
||||
}
|
||||
|
||||
$targetWidth = $destinationWidth;
|
||||
$targetHeight = $destinationHeight;
|
||||
|
||||
$destImage = imagecreatetruecolor($destinationWidth, $destinationHeight);
|
||||
|
||||
// If image is a PNG and the output is PNG, fill with transparency. Else fill with white background.
|
||||
if ($fileType == 'png' && $type == IMAGETYPE_PNG) {
|
||||
imagealphablending($destImage, false);
|
||||
imagesavealpha($destImage, true);
|
||||
$transparent = imagecolorallocatealpha($destImage, $red, $green, $blue, 127);
|
||||
imagefilledrectangle($destImage, 0, 0, $destinationWidth, $destinationHeight, $transparent);
|
||||
} else {
|
||||
$white = imagecolorallocate($destImage, $red, $green, $blue);
|
||||
imagefilledrectangle($destImage, 0, 0, $destinationWidth, $destinationHeight, $white);
|
||||
}
|
||||
|
||||
//$src_image = ImageManager::create($type, $src_file);
|
||||
if ($rotate) {
|
||||
$srcImage = imagerotate($srcImage, $rotate, 0);
|
||||
}
|
||||
|
||||
if ($destinationWidth >= $sourceWidth && $destinationHeight >= $sourceHeight) {
|
||||
imagecopyresized($destImage, $srcImage, (int) (($destinationWidth - $nextWidth) / 2),
|
||||
(int) (($destinationHeight - $nextHeight) / 2), 0, 0, $nextWidth, $nextHeight, $sourceWidth,
|
||||
$sourceHeight);
|
||||
} else {
|
||||
ImageManager::imagecopyresampled($destImage, $srcImage, (int) (($destinationWidth - $nextWidth) / 2),
|
||||
(int) (($destinationHeight - $nextHeight) / 2), 0, 0, $nextWidth, $nextHeight, $sourceWidth,
|
||||
$sourceHeight, $quality);
|
||||
}
|
||||
$writeFile = ImageManager::write($fileType, $destImage, $destinationFile);
|
||||
@imagedestroy($srcImage);
|
||||
return $writeFile;
|
||||
} else {
|
||||
$psImageGenerationMethod = Configuration::get('PS_IMAGE_GENERATION_METHOD');
|
||||
if ($widthDiff > 1 && $heightDiff > 1) {
|
||||
$nextWidth = $sourceWidth;
|
||||
$nextHeight = $sourceHeight;
|
||||
} else {
|
||||
if ($psImageGenerationMethod == 2 || (!$psImageGenerationMethod && $widthDiff < $heightDiff)) {
|
||||
$nextHeight = $destinationHeight;
|
||||
$nextWidth = round(($sourceWidth * $nextHeight) / $sourceHeight);
|
||||
$destinationWidth = (int) (!$psImageGenerationMethod ? $destinationWidth : $nextWidth);
|
||||
} else {
|
||||
$nextWidth = $destinationWidth;
|
||||
$nextHeight = round($sourceHeight * $destinationWidth / $sourceWidth);
|
||||
$destinationHeight = (int) (!$psImageGenerationMethod ? $destinationHeight : $nextHeight);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ImageManager::checkImageMemoryLimit($sourceFile)) {
|
||||
return !($error = self::ERROR_MEMORY_LIMIT);
|
||||
}
|
||||
|
||||
$targetWidth = $destinationWidth;
|
||||
$targetHeight = $destinationHeight;
|
||||
|
||||
$destImage = imagecreatetruecolor($destinationWidth, $destinationHeight);
|
||||
|
||||
// If image is a PNG and the output is PNG, fill with transparency. Else fill with white background.
|
||||
if ($fileType == 'png' && $type == IMAGETYPE_PNG) {
|
||||
imagealphablending($destImage, false);
|
||||
imagesavealpha($destImage, true);
|
||||
$transparent = imagecolorallocatealpha($destImage, $red, $green, $blue, 127);
|
||||
imagefilledrectangle($destImage, 0, 0, $destinationWidth, $destinationHeight, $transparent);
|
||||
} else {
|
||||
$white = imagecolorallocate($destImage, $red, $green, $blue);
|
||||
imagefilledrectangle($destImage, 0, 0, $destinationWidth, $destinationHeight, $white);
|
||||
}
|
||||
|
||||
//$src_image = ImageManager::create($type, $src_file);
|
||||
if ($rotate) {
|
||||
$srcImage = imagerotate($srcImage, $rotate, 0);
|
||||
}
|
||||
|
||||
$originConfig = Configuration::get('GMCROP_ORIGIN');
|
||||
switch ($originConfig) {
|
||||
case 0:
|
||||
$originX = 0;
|
||||
$originY = 0;
|
||||
break;
|
||||
case 1:
|
||||
$originX = (int) (($destinationWidth - $nextWidth) / 2);
|
||||
$originY = 0;
|
||||
break;
|
||||
case 2:
|
||||
$originX = (int) ($destinationWidth - $nextWidth);
|
||||
$originY = 0;
|
||||
break;
|
||||
case 3:
|
||||
$originX = 0;
|
||||
$originY = (int) (($destinationHeight - $nextHeight) / 2);
|
||||
break;
|
||||
case 4:
|
||||
$originX = (int) (($destinationWidth - $nextWidth) / 2);
|
||||
$originY = (int) (($destinationHeight - $nextHeight) / 2);
|
||||
break;
|
||||
case 5:
|
||||
$originX = (int) ($destinationWidth - $nextWidth);
|
||||
$originY = (int) (($destinationHeight - $nextHeight) / 2);
|
||||
break;
|
||||
case 6:
|
||||
$originX = 0;
|
||||
$originY = (int) (($destinationHeight - $nextHeight));
|
||||
break;
|
||||
case 7:
|
||||
$originX = (int) (($destinationWidth - $nextWidth) / 2);
|
||||
$originY = (int) (($destinationHeight - $nextHeight));
|
||||
break;
|
||||
case 8:
|
||||
$originX = (int) ($destinationWidth - $nextWidth);
|
||||
$originY = (int) (($destinationHeight - $nextHeight));
|
||||
break;
|
||||
default:
|
||||
$originX = (int) (($destinationWidth - $nextWidth) / 2);
|
||||
$originY = (int) (($destinationHeight - $nextHeight) / 2);
|
||||
break;
|
||||
}
|
||||
if ($destinationWidth >= $sourceWidth && $destinationHeight >= $sourceHeight) {
|
||||
imagecopyresized($destImage, $srcImage, $originX, $originY, 0, 0, $nextWidth, $nextHeight, $sourceWidth,
|
||||
$sourceHeight);
|
||||
} else {
|
||||
ImageManager::imagecopyresampled($destImage, $srcImage, $originX, $originY, 0, 0, $nextWidth,
|
||||
$nextHeight, $sourceWidth, $sourceHeight, $quality);
|
||||
}
|
||||
$writeFile = ImageManager::write($fileType, $destImage, $destinationFile);
|
||||
Hook::exec('actionOnImageResizeAfter', array('dst_file' => $destinationFile, 'file_type' => $fileType));
|
||||
@imagedestroy($srcImage);
|
||||
|
||||
file_put_contents(
|
||||
dirname($destinationFile).DIRECTORY_SEPARATOR.'fileType', $fileType
|
||||
);
|
||||
return $writeFile;
|
||||
}
|
||||
}
|
||||
|
||||
public static function hex2rgb($hex)
|
||||
{
|
||||
$hex = str_replace("#", "", $hex);
|
||||
if (strlen($hex) == 3) {
|
||||
$r = hexdec(substr($hex, 0, 1).substr($hex, 0, 1));
|
||||
$g = hexdec(substr($hex, 1, 1).substr($hex, 1, 1));
|
||||
$b = hexdec(substr($hex, 2, 1).substr($hex, 2, 1));
|
||||
} else {
|
||||
$r = hexdec(substr($hex, 0, 2));
|
||||
$g = hexdec(substr($hex, 2, 2));
|
||||
$b = hexdec(substr($hex, 4, 2));
|
||||
}
|
||||
$rgb = array($r, $g, $b);
|
||||
return $rgb; // returns an array with the rgb values
|
||||
}
|
||||
}
|
||||
35
modules/gmcrop/override/classes/index.php
Normal file
35
modules/gmcrop/override/classes/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2015 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
35
modules/gmcrop/override/index.php
Normal file
35
modules/gmcrop/override/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2015 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
0
modules/gmcrop/translations/de.php
Normal file
0
modules/gmcrop/translations/de.php
Normal file
12
modules/gmcrop/translations/fr.php
Normal file
12
modules/gmcrop/translations/fr.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_cef9faf91287c61a2b6d034b894ef9f3'] = 'Kadruj obrazy zamiast dodawać białą przestrzeń wokół nich';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_c888438d14855d7d96a2724ee9c306bd'] = 'Zapisano ustawienia';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_c28f778d1501649f6dd112171bb39113'] = 'Rodzaje obrazów podlegające kadrowaniu';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_c9cc8cce247e49bae79f15173ce97354'] = 'Zapisz';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_f4f70727dc34561dfde1a3c529b6205c'] = 'Ustawienia';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_7a56f25cfeb8d30a3d1fa6df967cd044'] = 'Początek kadrowania';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_93cba07454f06a4a960172bbd6e2a435'] = 'Tak';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_bafd7322c6e97d25b6299b5d6fe8920b'] = 'Nie';
|
||||
16
modules/gmcrop/translations/pl.php
Normal file
16
modules/gmcrop/translations/pl.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_cef9faf91287c61a2b6d034b894ef9f3'] = 'Kadruj obrazy zamiast dodawać białą przestrzeń wokół nich';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_c888438d14855d7d96a2724ee9c306bd'] = 'Zapisano ustawienia';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_c9cc8cce247e49bae79f15173ce97354'] = 'Zapisz';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_f4f70727dc34561dfde1a3c529b6205c'] = 'Ustawienia';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_8ada2cd27770849b812f52a0425f72a0'] = 'Wyodrębnij produkt z tła';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_2ab399b30ad512851b91bb6dec126900'] = 'Usuwa białe lub przezroczyste tło wokół produktu na oryginalnym obrazie.';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_d4e2a4ea8a93f4dbda9936e222f4549a'] = 'Zachowaj proporcje dla obrazów typu:';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_893385c76dd11a8f89622abbd2a788b9'] = 'Kadruj obrazy typu:';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_7a56f25cfeb8d30a3d1fa6df967cd044'] = 'Początek kadrowania';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_93cba07454f06a4a960172bbd6e2a435'] = 'Tak';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_bafd7322c6e97d25b6299b5d6fe8920b'] = 'Nie';
|
||||
$_MODULE['<{gmcrop}prestashop>gmcrop_368d9ac76af05f714092bc808a426bfc'] = 'Kolor tła';
|
||||
Reference in New Issue
Block a user