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

Allow Semi-transparent member profile-image #2243

Merged
6 commits merged into from
Mar 20, 2018
Merged
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
22 changes: 20 additions & 2 deletions classes/file/FileHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,10 @@ function checkMemoryLoadImage(&$imageInfo)
* @param int $resize_height Height to resize
* @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type
* @param string $thumbnail_type Thumbnail type(crop, ratio)
* @param bool $thumbnail_transparent If $target_type is png, set background set transparent color
* @return bool TRUE: success, FALSE: failed
*/
function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop')
function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop', $thumbnail_transparent = FALSE)
{
// check params
if (($source_file = self::exists($source_file)) === FALSE)
Expand Down Expand Up @@ -841,7 +842,24 @@ function createImageFile($source_file, $target_file, $resize_width = 0, $resize_
return FALSE;
}

imagefilledrectangle($thumb, 0, 0, $resize_width - 1, $resize_height - 1, imagecolorallocate($thumb, 255, 255, 255));
if(function_exists('imagecolorallocatealpha') && $target_type == 'png' && $thumbnail_transparent)
{
imagefill($thumb, 0, 0, imagecolorallocatealpha($thumb, 0, 0, 0, 127));

if(function_exists('imagesavealpha'))
{
imagesavealpha($thumb, TRUE);
}

if(function_exists('imagealphablending'))
{
imagealphablending($thumb, TRUE);
}
}
else
{
imagefilledrectangle($thumb, 0, 0, $resize_width - 1, $resize_height - 1, imagecolorallocate($thumb, 255, 255, 255));
}

// create temporary image having original type
$source = NULL;
Expand Down
5 changes: 5 additions & 0 deletions modules/member/lang/lang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2806,4 +2806,9 @@
<value xml:lang="en"><![CDATA[Warning! Please remember current site setting doesn't accept new member.]]></value>
<value xml:lang="jp"><![CDATA[注意!現在のサイト設定は、会員登録を許可していないということを覚えなさい。]]></value>
</item>
<item name="allow_transparent_thumbnail">
<value xml:lang="ko"><![CDATA[리사이즈 이미지에 투명 배경을 허용합니다. (PNG only)]]></value>
<value xml:lang="en"><![CDATA[Allow transparent background on resized image (PNG only)]]></value>
<value xml:lang="jp"><![CDATA[サイズ変更した画像に透明な背景を許可します。(PNG only)]]></value>
</item>
</lang>
1 change: 1 addition & 0 deletions modules/member/member.admin.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public function procMemberAdminInsertSignupConfig()
$signupItem->max_width = $all_args->{$key.'_max_width'};
$signupItem->max_height = $all_args->{$key.'_max_height'};
$signupItem->max_filesize = $all_args->{$key.'_max_filesize'};
$signupItem->allow_transparent_thumbnail = $all_args->{$key.'_transparent_thumbnail'};
}

// set extends form
Expand Down
7 changes: 6 additions & 1 deletion modules/member/member.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,11 @@ function insertProfileImage($member_srl, $target_file)
$max_width = $config->profile_image_max_width;
$max_height = $config->profile_image_max_height;
$max_filesize = $config->profile_image_max_filesize;
foreach($config->signupForm as $val)
{
if($val->name == "profile_image")
$allow_transparent = $val->allow_transparent_thumbnail == 'Y';
}

Context::loadLang(_XE_PATH_ . 'modules/file/lang');

Expand All @@ -789,7 +794,7 @@ function insertProfileImage($member_srl, $target_file)
if(($width > $max_width || $height > $max_height ) && $type != 1)
{
$temp_filename = sprintf('files/cache/tmp/profile_image_%d.%s', $member_srl, $ext);
FileHandler::createImageFile($target_file, $temp_filename, $max_width, $max_height, $ext);
FileHandler::createImageFile($target_file, $temp_filename, $max_width, $max_height, $ext, 'crop', $allow_transparent);

// 파일 용량 제한
FileHandler::clearStatCache($temp_filename);
Expand Down
1 change: 1 addition & 0 deletions modules/member/tpl/signup_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<label for="{$item->name}_max_width" class="x_inline">{$lang->cmd_image_max_width} <input type="number" min="1" name="{$item->name}_max_width" id="{$item->name}_max_width" value="{$item->max_width}" /> px</label>
<label for="{$item->name}_max_height" class="x_inline">{$lang->cmd_image_max_height} <input type="number" min="1" name="{$item->name}_max_height" id="{$item->name}_max_height" value="{$item->max_height}" /> px</label>
<label for="{$item->name}_max_filesize">{$lang->allowed_filesize} : <input type="number" min="1" name="{$item->name}_max_filesize" id="{$item->name}_max_filesize" value="{$item->max_filesize}" /> KB</label>
<label for="{$item->name}_transparent_thumbnail" cond="$item->name == 'profile_image'"><input type="checkbox" value="Y" name="{$item->name}_transparent_thumbnail" id="{$item->name}_transparent_thumbnail" checked="checked"|cond="$item->allow_transparent_thumbnail" /> {$lang->allow_transparent_thumbnail}</label>
</div>

<div cond="$item->name == 'signature'" class="_subItem" style="display:none;padding-top:5px"|cond="!$item->isUse">
Expand Down