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

Update ImageProcessing.php #1

Open
wants to merge 7 commits into
base: patch-9
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions oc-admin/controller/settings/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ function doModel()
$forceJPEG = Params::getParam('force_jpeg');
$use_imagick = Params::getParam('use_imagick');
$type_watermark = Params::getParam('watermark_type');
$watermark_color = Params::getParam('watermark_text_color');
$watermark_text = Params::getParam('watermark_text');
$watermark_text = Params::getParam('watermark_text');
$watermark_text_size = Params::getParam('watermark_text_size');
$watermark_text_color = Params::getParam('watermark_text_color');

switch ($type_watermark) {
case 'none':
$iUpdated += osc_set_preference('watermark_text_color', '');
$iUpdated += osc_set_preference('watermark_text', '');
$iUpdated += osc_set_preference('watermark_text_size', '');
$iUpdated += osc_set_preference('watermark_text_color', '');
$iUpdated += osc_set_preference('watermark_image', '');
break;
case 'text':
$iUpdated += osc_set_preference('watermark_text_color', $watermark_color);
$iUpdated += osc_set_preference('watermark_text', $watermark_text);
$iUpdated += osc_set_preference('watermark_text_size', $watermark_text_size);
$iUpdated += osc_set_preference('watermark_text_color', $watermark_text_color);
$iUpdated += osc_set_preference('watermark_image', '');
$iUpdated += osc_set_preference('watermark_place', Params::getParam('watermark_text_place'));
break;
Expand All @@ -91,8 +94,9 @@ function doModel()
$error .= _m('There was a problem uploading the watermark image')."<br />";
}
}
$iUpdated += osc_set_preference('watermark_text_color', '');
$iUpdated += osc_set_preference('watermark_text', '');
$iUpdated += osc_set_preference('watermark_text_size', '');
$iUpdated += osc_set_preference('watermark_text_color', '');
$iUpdated += osc_set_preference('watermark_place', Params::getParam('watermark_image_place'));
break;
default:
Expand Down
6 changes: 6 additions & 0 deletions oc-admin/themes/modern/settings/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ function customPageTitle($string) {
<input type="text" class="large" name="watermark_text" value="<?php echo osc_esc_html( osc_watermark_text() ); ?>" />
</div>
</div>
<div class="form-row">
<div class="form-label"><?php _e('Size'); ?></div>
<div class="form-controls">
<input type="text" class="large" name="watermark_text_size" value="<?php echo osc_esc_html( osc_watermark_text_size() ); ?>" />
</div>
</div>
<div class="form-row">
<div class="form-label"><?php _e('Color'); ?></div>
<div class="form-controls">
Expand Down
2 changes: 1 addition & 1 deletion oc-includes/osclass/ItemActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ public function uploadItemResources($aResources,$itemId)
$size = explode('x', osc_normal_dimensions());
$img = ImageResizer::fromFile($tmpName)->autoRotate()->resizeTo($size[0], $size[1]);
if( osc_is_watermark_text() ) {
$img->doWatermarkText(osc_watermark_text(), osc_watermark_text_color());
$img->doWatermarkText(osc_watermark_text(), osc_watermark_text_color(), osc_watermark_text_size());
} else if ( osc_is_watermark_image() ){
$img->doWatermarkImage();
}
Expand Down
6 changes: 3 additions & 3 deletions oc-includes/osclass/classes/ImageProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ public function show() {
}
}

public function doWatermarkText($text, $color = 'ff0000') {
public function doWatermarkText($text, $color = 'ff0000', $fontsize = '30') {
$this->_watermarked = true;
$this->_font = osc_apply_filter('watermark_font_path', LIB_PATH . "osclass/assets/fonts/Arial.ttf");
if(osc_use_imagick()) {
$draw = new ImagickDraw();
$draw->setFillColor("#".$color);
$draw->setFont($this->_font);
$draw->setFontSize( 30 );
$draw->setFontSize( $fontsize );
$metrics = $this->im->queryFontMetrics($draw, $text);
switch(osc_watermark_place()) {
case 'tl':
Expand Down Expand Up @@ -289,7 +289,7 @@ public function doWatermarkText($text, $color = 'ff0000') {
}
$color = $this->_imageColorAllocateHex($color);
$offset = $this->_calculateOffset($text);
imagettftext($this->im, 20, 0, $offset['x'], $offset['y'], $color, $this->_font , html_entity_decode($text, null, "UTF-8"));
imagettftext($this->im, $fontsize, 0, $offset['x'], $offset['y'], $color, $this->_font , html_entity_decode($text, null, "UTF-8"));
}
return $this;
}
Expand Down
21 changes: 15 additions & 6 deletions oc-includes/osclass/helpers/hPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1017,21 +1017,30 @@ function osc_is_watermark_image() {
}

/**
* Return watermark text color
* Return watermark text
*
* @return string
*/
function osc_watermark_text_color() {
return getPreference('watermark_text_color');
function osc_watermark_text() {
return getPreference('watermark_text');
}

/**
* Return watermark text
* Return watermark text size
*
* @return string
*/
function osc_watermark_text() {
return getPreference('watermark_text');
function osc_watermark_text_size() {
return getPreference('watermark_text_size');
}

/**
* Return watermark text color
*
* @return string
*/
function osc_watermark_text_color() {
return getPreference('watermark_text_color');
}

/**
Expand Down
1 change: 1 addition & 0 deletions oc-includes/osclass/installer/basic_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ INSERT INTO /*TABLE_PREFIX*/t_preference VALUES
,('osclass', 'marketCategories', '', 'STRING')
,('osclass', 'marketDataUpdate', '0', 'INTEGER')
,('osclass', 'watermark_text', '', 'STRING')
,('osclass', 'watermark_text_size', '30', 'STRING')
,('osclass', 'watermark_text_color', '', 'STRING')
,('osclass', 'watermark_place', 'centre', 'STRING')
,('osclass', 'watermark_image', '', 'STRING')
Expand Down
4 changes: 4 additions & 0 deletions oc-includes/osclass/upgrade-funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@
osc_set_preference('marketURL', 'http://market.osclass.org/api/v2/');
}

if(osc_version() < 357) {
osc_set_preference('watermark_text_size', '30');
}

osc_changeVersionTo(357);

if(!defined('IS_AJAX') || !IS_AJAX) {
Expand Down