Skip to content

Commit

Permalink
Added Crop option
Browse files Browse the repository at this point in the history
  • Loading branch information
renekreijveld committed Aug 3, 2017
1 parent 1dffd1c commit de6218f
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 12 deletions.
3 changes: 2 additions & 1 deletion source/plg_rsfp_imageresize/language/en-GB/en-GB.plg_system_rsfpimageresize.ini
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ RSFP_IMAGERESIZE_DO_MD_LABEL="Create medium"
RSFP_IMAGERESIZE_LG="Large"
RSFP_IMAGERESIZE_DO_LG_LABEL="Create large"
RSFP_IMAGERESIZE_WIDTH="Width"
RSFP_IMAGERESIZE_HEIGHT="Height"
RSFP_IMAGERESIZE_HEIGHT="Height"
RSFP_IMAGERESIZE_CROP_LABEL="Crop"
3 changes: 2 additions & 1 deletion source/plg_rsfp_imageresize/language/nl-NL/nl-NL.plg_system_rsfpimageresize.ini
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ RSFP_IMAGERESIZE_DO_MD_LABEL="Maak middel"
RSFP_IMAGERESIZE_LG="Groot"
RSFP_IMAGERESIZE_DO_LG_LABEL="Maak groot"
RSFP_IMAGERESIZE_WIDTH="Breedte"
RSFP_IMAGERESIZE_HEIGHT="Hoogte"
RSFP_IMAGERESIZE_HEIGHT="Hoogte"
RSFP_IMAGERESIZE_CROP_LABEL="Crop"
164 changes: 157 additions & 7 deletions source/plg_rsfp_imageresize/rsfpimageresize.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @version 1.2
* @version 1.3
* @package RSFPImageResize
* @copyright (C) 2017 www.renekreijveld.nl
* @license GPL, http://www.gnu.org/copyleft/gpl.html
Expand Down Expand Up @@ -38,18 +38,23 @@ public function rsfp_f_onAfterFileUpload($params)
$do_tn = RSFormProHelper::getConfig('imgresize_do_tn');
$tn_width = RSFormProHelper::getConfig('imgresize_tn_width');
$tn_height = RSFormProHelper::getConfig('imgresize_tn_height');
$tn_crop = RSFormProHelper::getConfig('imgresize_tn_crop');
$do_xs = RSFormProHelper::getConfig('imgresize_do_xs');
$xs_width = RSFormProHelper::getConfig('imgresize_xs_width');
$xs_height = RSFormProHelper::getConfig('imgresize_xs_height');
$xs_crop = RSFormProHelper::getConfig('imgresize_xs_crop');
$do_sm = RSFormProHelper::getConfig('imgresize_do_sm');
$sm_width = RSFormProHelper::getConfig('imgresize_sm_width');
$sm_height = RSFormProHelper::getConfig('imgresize_sm_height');
$sm_crop = RSFormProHelper::getConfig('imgresize_sm_crop');
$do_md = RSFormProHelper::getConfig('imgresize_do_md');
$md_width = RSFormProHelper::getConfig('imgresize_md_width');
$md_height = RSFormProHelper::getConfig('imgresize_md_height');
$md_crop = RSFormProHelper::getConfig('imgresize_tn_crop');
$do_lg = RSFormProHelper::getConfig('imgresize_do_lg');
$lg_width = RSFormProHelper::getConfig('imgresize_lg_width');
$lg_height = RSFormProHelper::getConfig('imgresize_lg_height');
$lg_crop = RSFormProHelper::getConfig('imgresize_tn_crop');

// Initialize logging
if ($imgresize_log == 1)
Expand All @@ -75,7 +80,14 @@ public function rsfp_f_onAfterFileUpload($params)
// Thumbnail
if (($tn_width > 0 || $tn_height > 0) && $do_tn == 1)
{
$image->resizeToBestFit($tn_width, $tn_height);
if ($tn_crop == 1)
{
$image->crop($tn_width, $tn_height);
}
else
{
$image->resizeToBestFit($tn_width, $tn_height);
}
$dst_width = floor($image->getDestWidth());
$dst_height = floor($image->getDestHeight());
$image->save($upload["dirname"] . '/' . $upload["filename"] . '-tn.' . $upload["extension"]);
Expand All @@ -85,7 +97,14 @@ public function rsfp_f_onAfterFileUpload($params)
// Extra small
if (($xs_width > 0 || $xs_height > 0) && $do_xs == 1)
{
$image->resizeToBestFit($xs_width, $xs_height);
if ($xs_crop == 1)
{
$image->crop($xs_width, $xs_height);
}
else
{
$image->resizeToBestFit($xs_width, $xs_height);
}
$dst_width = floor($image->getDestWidth());
$dst_height = floor($image->getDestHeight());
$image->save($upload["dirname"] . '/' . $upload["filename"] . '-xs.' . $upload["extension"]);
Expand All @@ -95,7 +114,14 @@ public function rsfp_f_onAfterFileUpload($params)
// Small
if (($sm_width > 0 || $sm_height > 0) && $do_sm == 1)
{
$image->resizeToBestFit($sm_width, $sm_height);
if ($sm_crop == 1)
{
$image->crop($sm_width, $sm_height);
}
else
{
$image->resizeToBestFit($sm_width, $sm_height);
}
$dst_width = floor($image->getDestWidth());
$dst_height = floor($image->getDestHeight());
$image->save($upload["dirname"] . '/' . $upload["filename"] . '-sm.' . $upload["extension"]);
Expand All @@ -105,7 +131,14 @@ public function rsfp_f_onAfterFileUpload($params)
// Medium
if (($md_width > 0 || $md_height > 0) && $do_md == 1)
{
$image->resizeToBestFit($md_width, $md_height);
if ($md_crop == 1)
{
$image->crop($md_width, $md_height);
}
else
{
$image->resizeToBestFit($md_width, $md_height);
}
$dst_width = floor($image->getDestWidth());
$dst_height = floor($image->getDestHeight());
$image->save($upload["dirname"] . '/' . $upload["filename"] . '-md.' . $upload["extension"]);
Expand All @@ -115,7 +148,14 @@ public function rsfp_f_onAfterFileUpload($params)
// Large
if (($lg_width > 0 || $lg_height > 0) && $do_lg == 1)
{
$image->resizeToBestFit($lg_width, $lg_height);
if ($lg_crop == 1)
{
$image->crop($lg_width, $lg_height);
}
else
{
$image->resizeToBestFit($lg_width, $lg_height);
}
$dst_width = floor($image->getDestWidth());
$dst_height = floor($image->getDestHeight());
$image->save($upload["dirname"] . '/' . $upload["filename"] . '-lg.' . $upload["extension"]);
Expand All @@ -136,18 +176,23 @@ public function imageresizeConfigurationScreen()
$do_tn = RSFormProHelper::getConfig('imgresize_do_tn');
$tn_width = RSFormProHelper::getConfig('imgresize_tn_width');
$tn_height = RSFormProHelper::getConfig('imgresize_tn_height');
$tn_crop = RSFormProHelper::getConfig('imgresize_tn_crop');
$do_xs = RSFormProHelper::getConfig('imgresize_do_xs');
$xs_width = RSFormProHelper::getConfig('imgresize_xs_width');
$xs_height = RSFormProHelper::getConfig('imgresize_xs_height');
$xs_crop = RSFormProHelper::getConfig('imgresize_xs_crop');
$do_sm = RSFormProHelper::getConfig('imgresize_do_sm');
$sm_width = RSFormProHelper::getConfig('imgresize_sm_width');
$sm_height = RSFormProHelper::getConfig('imgresize_sm_height');
$sm_crop = RSFormProHelper::getConfig('imgresize_sm_crop');
$do_md = RSFormProHelper::getConfig('imgresize_do_md');
$md_width = RSFormProHelper::getConfig('imgresize_md_width');
$md_height = RSFormProHelper::getConfig('imgresize_md_height');
$md_crop = RSFormProHelper::getConfig('imgresize_tn_crop');
$do_lg = RSFormProHelper::getConfig('imgresize_do_lg');
$lg_width = RSFormProHelper::getConfig('imgresize_lg_width');
$lg_height = RSFormProHelper::getConfig('imgresize_lg_height'); ?>
$lg_height = RSFormProHelper::getConfig('imgresize_lg_height');
$lg_crop = RSFormProHelper::getConfig('imgresize_tn_crop');?>
<div id="page-imageresize">
<fieldset class="adminform form-horizontal">
<h3><?php echo JText::_('RSFP_IMAGERESIZE_LOGGING'); ?></h3>
Expand Down Expand Up @@ -216,6 +261,27 @@ public function imageresizeConfigurationScreen()
id="rsformConfig_imgresize_tn_height" value="<?php echo $tn_height; ?>"/>
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="rsformConfig_imgresize_tn_crop-lbl" for="rsformConfig_imgresize_tn_crop">
<?php echo JText::_('RSFP_IMAGERESIZE_CROP_LABEL'); ?>
</label>
</div>
<div class="controls">
<fieldset id="rsformConfig_imgresize_tn_crop" class="btn-group radio">
<input type="radio" id="rsformConfig_imgresize_tn_crop1" name="rsformConfig[imgresize_tn_crop]"
value="1" <?php if ($tn_crop == 1) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_tn_crop1">
<?php echo JText::_('JYES'); ?>
</label>
<input type="radio" id="rsformConfig_imgresize_tn_crop0" name="rsformConfig[imgresize_tn_crop]"
value="0" <?php if ($tn_crop == 0) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_tn_crop0">
<?php echo JText::_('JNO'); ?>
</label>
</fieldset>
</div>
</div>
<h3><?php echo JText::_('RSFP_IMAGERESIZE_XS'); ?></h3>
<div class="control-group">
<div class="control-label">
Expand Down Expand Up @@ -260,6 +326,27 @@ public function imageresizeConfigurationScreen()
id="rsformConfig_imgresize_xs_height" value="<?php echo $xs_height; ?>"/>
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="rsformConfig_imgresize_xs_crop-lbl" for="rsformConfig_imgresize_xs_crop">
<?php echo JText::_('RSFP_IMAGERESIZE_CROP_LABEL'); ?>
</label>
</div>
<div class="controls">
<fieldset id="rsformConfig_imgresize_xs_crop" class="btn-group radio">
<input type="radio" id="rsformConfig_imgresize_xs_crop1" name="rsformConfig[imgresize_xs_crop]"
value="1" <?php if ($xs_crop == 1) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_xs_crop1">
<?php echo JText::_('JYES'); ?>
</label>
<input type="radio" id="rsformConfig_imgresize_xs_crop0" name="rsformConfig[imgresize_xs_crop]"
value="0" <?php if ($xs_crop == 0) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_xs_crop0">
<?php echo JText::_('JNO'); ?>
</label>
</fieldset>
</div>
</div>
<h3><?php echo JText::_('RSFP_IMAGERESIZE_SM'); ?></h3>
<div class="control-group">
<div class="control-label">
Expand Down Expand Up @@ -304,6 +391,27 @@ public function imageresizeConfigurationScreen()
id="rsformConfig_imgresize_sm_height" value="<?php echo $sm_height; ?>"/>
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="rsformConfig_imgresize_sm_crop-lbl" for="rsformConfig_imgresize_sm_crop">
<?php echo JText::_('RSFP_IMAGERESIZE_CROP_LABEL'); ?>
</label>
</div>
<div class="controls">
<fieldset id="rsformConfig_imgresize_sm_crop" class="btn-group radio">
<input type="radio" id="rsformConfig_imgresize_sm_crop1" name="rsformConfig[imgresize_sm_crop]"
value="1" <?php if ($sm_crop == 1) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_sm_crop1">
<?php echo JText::_('JYES'); ?>
</label>
<input type="radio" id="rsformConfig_imgresize_sm_crop0" name="rsformConfig[imgresize_sm_crop]"
value="0" <?php if ($sm_crop == 0) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_sm_crop0">
<?php echo JText::_('JNO'); ?>
</label>
</fieldset>
</div>
</div>
<h3><?php echo JText::_('RSFP_IMAGERESIZE_MD'); ?></h3>
<div class="control-group">
<div class="control-label">
Expand Down Expand Up @@ -348,6 +456,27 @@ public function imageresizeConfigurationScreen()
id="rsformConfig_imgresize_md_height" value="<?php echo $md_height; ?>"/>
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="rsformConfig_imgresize_md_crop-lbl" for="rsformConfig_imgresize_md_crop">
<?php echo JText::_('RSFP_IMAGERESIZE_CROP_LABEL'); ?>
</label>
</div>
<div class="controls">
<fieldset id="rsformConfig_imgresize_md_crop" class="btn-group radio">
<input type="radio" id="rsformConfig_imgresize_md_crop1" name="rsformConfig[imgresize_md_crop]"
value="1" <?php if ($md_crop == 1) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_md_crop1">
<?php echo JText::_('JYES'); ?>
</label>
<input type="radio" id="rsformConfig_imgresize_md_crop0" name="rsformConfig[imgresize_md_crop]"
value="0" <?php if ($md_crop == 0) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_md_crop0">
<?php echo JText::_('JNO'); ?>
</label>
</fieldset>
</div>
</div>
<h3><?php echo JText::_('RSFP_IMAGERESIZE_LG'); ?></h3>
<div class="control-group">
<div class="control-label">
Expand Down Expand Up @@ -392,6 +521,27 @@ public function imageresizeConfigurationScreen()
id="rsformConfig_imgresize_lg_height" value="<?php echo $lg_height; ?>"/>
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="rsformConfig_imgresize_lg_crop-lbl" for="rsformConfig_imgresize_lg_crop">
<?php echo JText::_('RSFP_IMAGERESIZE_CROP_LABEL'); ?>
</label>
</div>
<div class="controls">
<fieldset id="rsformConfig_imgresize_lg_crop" class="btn-group radio">
<input type="radio" id="rsformConfig_imgresize_lg_crop1" name="rsformConfig[imgresize_lg_crop]"
value="1" <?php if ($lg_crop == 1) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_lg_crop1">
<?php echo JText::_('JYES'); ?>
</label>
<input type="radio" id="rsformConfig_imgresize_lg_crop0" name="rsformConfig[imgresize_lg_crop]"
value="0" <?php if ($lg_crop == 0) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_lg_crop0">
<?php echo JText::_('JNO'); ?>
</label>
</fieldset>
</div>
</div>
</fieldset>
</div>
<?php
Expand Down
2 changes: 1 addition & 1 deletion source/plg_rsfp_imageresize/rsfpimageresize.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<license>GNU General Public License version 3</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.renekreijveld.nl</authorUrl>
<version>1.2</version>
<version>1.3</version>
<description><![CDATA[PLG_SYSTEM_RSFPIMAGERESIZE_DESC]]></description>
<scriptfile>script.php</scriptfile>

Expand Down
2 changes: 1 addition & 1 deletion source/plg_rsfp_imageresize/script.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @version 1.2
* @version 1.3
* @package RSFPImageResize
* @copyright (C) 2017 www.renekreijveld.nl
* @license GPL, http://www.gnu.org/copyleft/gpl.html
Expand Down
7 changes: 6 additions & 1 deletion source/plg_rsfp_imageresize/sql/mysql/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('i
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_do_tn', '1');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_tn_width', '150');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_tn_height', '150');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_tn_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_do_xs', '1');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_xs_width', '300');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_xs_height', '200');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_xs_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_do_sm', '1');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_sm_width', '768');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_sm_height', '512');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_sm_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_do_md', '1');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_md_width', '1024');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_md_height', '683');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_md_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_do_lg', '1');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_lg_width', '1200');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_lg_height', '800');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_lg_height', '800');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_lg_crop', '0');

0 comments on commit de6218f

Please sign in to comment.