Skip to content

Commit

Permalink
Added allow enlarge option
Browse files Browse the repository at this point in the history
  • Loading branch information
renekreijveld committed Aug 3, 2017
1 parent 2820251 commit c0a9194
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PLG_SYSTEM_RSFPIMAGERESIZE_DESC="RSForm!Pro - Image Upload Resize plugin automat
RSFP_IMAGERESIZE_LABEL="Image upload resize"
RSFP_IMAGERESIZE_LOG_LABEL="Log image resizes"
RSFP_IMAGERESIZE_LOGGING="Logging"
RSFP_IMAGERESIZE_ENLARGE_LABEL="Allow enlarge"
RSFP_IMAGERESIZE_THUMBNAIL="Thumbnail"
RSFP_IMAGERESIZE_DO_TN_LABEL="Create thumbnail"
RSFP_IMAGERESIZE_XS="Extra small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PLG_SYSTEM_RSFPIMAGERESIZE_DESC="RSForm!Pro - Afbeelding Upload Resize plugin ve
RSFP_IMAGERESIZE_LABEL="Afbeelding upload resize"
RSFP_IMAGERESIZE_LOG_LABEL="Log afbeelding resizes"
RSFP_IMAGERESIZE_LOGGING="Logging"
RSFP_IMAGERESIZE_ENLARGE_LABEL="Vergroten toestaan"
RSFP_IMAGERESIZE_THUMBNAIL="Thumbnail"
RSFP_IMAGERESIZE_DO_TN_LABEL="Maak thumbnail"
RSFP_IMAGERESIZE_XS="Extra klein"
Expand Down
132 changes: 114 additions & 18 deletions source/plg_rsfp_imageresize/rsfpimageresize.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @version 1.3
* @version 1.4
* @package RSFPImageResize
* @copyright (C) 2017 www.renekreijveld.nl
* @license GPL, http://www.gnu.org/copyleft/gpl.html
Expand Down Expand Up @@ -35,6 +35,7 @@ public function rsfp_f_onAfterFileUpload($params)

// Get plugin settings
$imgresize_log = RSFormProHelper::getConfig('imgresize_log');
$do_enlarge = RSFormProHelper::getConfig('imgresize_enlarge');
$do_tn = RSFormProHelper::getConfig('imgresize_do_tn');
$tn_width = RSFormProHelper::getConfig('imgresize_tn_width');
$tn_height = RSFormProHelper::getConfig('imgresize_tn_height');
Expand Down Expand Up @@ -75,91 +76,164 @@ public function rsfp_f_onAfterFileUpload($params)
$org_width = $image->getSourceWidth();
$org_height = $image->getSourceHeight();

if ($imgresize_log == 1) JLog::add(JText::_('Start processing file ' . $name . ' ' . $org_width . 'x' . $org_height), JLog::INFO, 'imageupload');
if ($imgresize_log == 1) {
JLog::add(JText::_('Start processing file ' . $name . ' ' . $org_width . 'x' . $org_height), JLog::INFO, 'imageupload');
JLog::add(JText::_('Enlarge enabled: ' . $do_enlarge), JLog::INFO, 'imageupload');
}

// Thumbnail
if (($tn_width > 0 || $tn_height > 0) && $do_tn == 1)
{
if ($tn_crop == 1)
{
$image->crop($tn_width, $tn_height);
if ($do_enlarge == 1)
{
$image->crop($tn_width, $tn_height, $allow_enlarge = True);
}
else
{
$image->crop($tn_width, $tn_height);
}
}
else
{
$image->resizeToBestFit($tn_width, $tn_height);
{
if ($do_enlarge == 1)
{
$image->resizeToBestFit($tn_width, $tn_height, $allow_enlarge = True);
}
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"]);
if ($imgresize_log == 1) JLog::add(JText::_('Saved thumbnail version ' . $upload["filename"] . '-tn.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height), JLog::INFO, 'imageupload');
if ($imgresize_log == 1) JLog::add(JText::_('Saved thumbnail version ' . $upload["filename"] . '-tn.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height . ' Crop: ' . $tn_crop), JLog::INFO, 'imageupload');
}

// Extra small
if (($xs_width > 0 || $xs_height > 0) && $do_xs == 1)
{
if ($xs_crop == 1)
{
$image->crop($xs_width, $xs_height);
if ($do_enlarge == 1)
{
$image->crop($xs_width, $xs_height, $allow_enlarge = True);
}
else
{
$image->crop($xs_width, $xs_height);
}
}
else
{
$image->resizeToBestFit($xs_width, $xs_height);
if ($do_enlarge == 1)
{
$image->resizeToBestFit($xs_width, $xs_height, $allow_enlarge = True);
}
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"]);
if ($imgresize_log == 1) JLog::add(JText::_('Saved extra small version ' . $upload["filename"] . '-xs.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height), JLog::INFO, 'imageupload');
if ($imgresize_log == 1) JLog::add(JText::_('Saved extra small version ' . $upload["filename"] . '-xs.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height . ' Crop: ' . $xs_crop), JLog::INFO, 'imageupload');
}

// Small
if (($sm_width > 0 || $sm_height > 0) && $do_sm == 1)
{
if ($sm_crop == 1)
{
$image->crop($sm_width, $sm_height);
if ($do_enlarge == 1)
{
$image->crop($sm_width, $sm_height, $allow_enlarge = True);
}
else
{
$image->crop($sm_width, $sm_height);
}
}
else
{
$image->resizeToBestFit($sm_width, $sm_height);
if ($do_enlarge == 1)
{
$image->resizeToBestFit($sm_width, $sm_height, $allow_enlarge = True);
}
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"]);
if ($imgresize_log == 1) JLog::add(JText::_('Saved small version ' . $upload["filename"] . '-sm.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height), JLog::INFO, 'imageupload');
if ($imgresize_log == 1) JLog::add(JText::_('Saved small version ' . $upload["filename"] . '-sm.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height . ' Crop: ' . $sm_crop), JLog::INFO, 'imageupload');
}

// Medium
if (($md_width > 0 || $md_height > 0) && $do_md == 1)
{
if ($md_crop == 1)
{
$image->crop($md_width, $md_height);
if ($do_enlarge == 1)
{
$image->crop($md_width, $md_height, $allow_enlarge = True);
}
else
{
$image->crop($md_width, $md_height);
}
}
else
{
$image->resizeToBestFit($md_width, $md_height);
if ($do_enlarge == 1)
{
$image->resizeToBestFit($md_width, $md_height, $allow_enlarge = True);
}
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"]);
if ($imgresize_log == 1) JLog::add(JText::_('Saved medium version ' . $upload["filename"] . '-md.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height), JLog::INFO, 'imageupload');
if ($imgresize_log == 1) JLog::add(JText::_('Saved medium version ' . $upload["filename"] . '-md.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height . ' Crop: ' . $md_crop), JLog::INFO, 'imageupload');
}

// Large
if (($lg_width > 0 || $lg_height > 0) && $do_lg == 1)
{
if ($lg_crop == 1)
{
$image->crop($lg_width, $lg_height);
if ($do_enlarge == 1)
{
$image->crop($lg_width, $lg_height, $allow_enlarge = True);
}
else
{
$image->crop($lg_width, $lg_height);
}
}
else
{
$image->resizeToBestFit($lg_width, $lg_height);
if ($do_enlarge == 1)
{
$image->resizeToBestFit($lg_width, $lg_height, $allow_enlarge = True);
}
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"]);
if ($imgresize_log == 1) JLog::add(JText::_('Saved large version ' . $upload["filename"] . '-lg.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height), JLog::INFO, 'imageupload');
if ($imgresize_log == 1) JLog::add(JText::_('Saved large version ' . $upload["filename"] . '-lg.' . $upload["extension"] . ' ' . $dst_width . 'x' . $dst_height . ' Crop: ' . $lg_crop), JLog::INFO, 'imageupload');
}

if ($imgresize_log == 1) JLog::add(JText::_('End RSFP Image Resize'), JLog::INFO, 'imageupload');
Expand All @@ -173,6 +247,7 @@ public function imageresizeConfigurationScreen()

ob_start();
$imgresize_log = RSFormProHelper::getConfig('imgresize_log');
$do_enlarge = RSFormProHelper::getConfig('imgresize_enlarge');
$do_tn = RSFormProHelper::getConfig('imgresize_do_tn');
$tn_width = RSFormProHelper::getConfig('imgresize_tn_width');
$tn_height = RSFormProHelper::getConfig('imgresize_tn_height');
Expand Down Expand Up @@ -217,6 +292,27 @@ public function imageresizeConfigurationScreen()
</fieldset>
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="rsformConfig_imgresize_enlarge-lbl" for="rsformConfig_imgresize_enlarge">
<?php echo JText::_('RSFP_IMAGERESIZE_ENLARGE_LABEL'); ?>
</label>
</div>
<div class="controls">
<fieldset id="rsformConfig_imgresize_enlarge" class="btn-group radio">
<input type="radio" id="rsformConfig_imgresize_enlarge1" name="rsformConfig[imgresize_enlarge]"
value="1" <?php if ($do_enlarge == 1) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_enlarge1">
<?php echo JText::_('JYES'); ?>
</label>
<input type="radio" id="rsformConfig_imgresize_enlarge0" name="rsformConfig[imgresize_enlarge]"
value="0" <?php if ($do_enlarge == 0) echo 'checked="checked"'; ?> />
<label for="rsformConfig_imgresize_enlarge0">
<?php echo JText::_('JNO'); ?>
</label>
</fieldset>
</div>
</div>
<h3><?php echo JText::_('RSFP_IMAGERESIZE_THUMBNAIL'); ?></h3>
<div class="control-group">
<div class="control-label">
Expand Down
8 changes: 6 additions & 2 deletions 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.3</version>
<version>1.4</version>
<description><![CDATA[PLG_SYSTEM_RSFPIMAGERESIZE_DESC]]></description>
<scriptfile>script.php</scriptfile>

Expand All @@ -21,7 +21,11 @@
<file driver="mysql" charset="utf8">sql/mysql/uninstall.sql</file>
</sql>
</uninstall>

<update>
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>
<files>
<folder>sql</folder>
<folder>vendor</folder>
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.3
* @version 1.4
* @package RSFPImageResize
* @copyright (C) 2017 www.renekreijveld.nl
* @license GPL, http://www.gnu.org/copyleft/gpl.html
Expand Down
3 changes: 2 additions & 1 deletion source/plg_rsfp_imageresize/sql/mysql/install.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_log', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_enlarge', '0');
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');
Expand All @@ -18,4 +19,4 @@ INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('i
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_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_lg_crop', '0');
5 changes: 5 additions & 0 deletions source/plg_rsfp_imageresize/sql/updates/mysql/1.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_tn_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_xs_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_sm_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_md_crop', '0');
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_lg_crop', '0');
1 change: 1 addition & 0 deletions source/plg_rsfp_imageresize/sql/updates/mysql/1.4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT IGNORE INTO `#__rsform_config` (`SettingName`, `SettingValue`) VALUES ('imgresize_enlarge', '0');

0 comments on commit c0a9194

Please sign in to comment.