Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shirne committed Aug 11, 2024
1 parent a38a1f9 commit 7741bee
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 41 deletions.
49 changes: 25 additions & 24 deletions src/extend/shirne/common/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@

use think\Exception;

define('UTF32_BIG_ENDIAN_BOM', chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF));
define('UTF32_LITTLE_ENDIAN_BOM', chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00));
define('UTF16_BIG_ENDIAN_BOM', chr(0xFE) . chr(0xFF));
define('UTF16_LITTLE_ENDIAN_BOM', chr(0xFF) . chr(0xFE));
define('UTF8_BOM', chr(0xEF) . chr(0xBB) . chr(0xBF));

class Encoding
{
const UTF32_BIG_ENDIAN_BOM = chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF);
const UTF32_LITTLE_ENDIAN_BOM = chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00);
const UTF16_BIG_ENDIAN_BOM = chr(0xFE) . chr(0xFF);
const UTF16_LITTLE_ENDIAN_BOM = chr(0xFF) . chr(0xFE);
const UTF8_BOM = chr(0xEF) . chr(0xBB) . chr(0xBF);



public static function detect($string)
{
$encoding=mb_detect_encoding($string);
if($encoding === false){
$encoding=self::_detect_utf_encoding($string);
$encoding = mb_detect_encoding($string);
if ($encoding === false) {
$encoding = self::_detect_utf_encoding($string);
}
return $encoding;
}
private static function _detect_utf_encoding($text) {
private static function _detect_utf_encoding($text)
{
$first2 = substr($text, 0, 2);
$first3 = substr($text, 0, 3);
$first4 = substr($text, 0, 3);
if ($first3 == self::UTF8_BOM)

if ($first3 == UTF8_BOM)
return 'UTF-8';
elseif ($first4 == self::UTF32_BIG_ENDIAN_BOM)
elseif ($first4 == UTF32_BIG_ENDIAN_BOM)
return 'UTF-32BE';
elseif ($first4 == self::UTF32_LITTLE_ENDIAN_BOM)
elseif ($first4 == UTF32_LITTLE_ENDIAN_BOM)
return 'UTF-32LE';
elseif ($first2 == self::UTF16_BIG_ENDIAN_BOM)
elseif ($first2 == UTF16_BIG_ENDIAN_BOM)
return 'UTF-16BE';
elseif ($first2 == self::UTF16_LITTLE_ENDIAN_BOM)
elseif ($first2 == UTF16_LITTLE_ENDIAN_BOM)
return 'UTF-16LE';

return false;
Expand All @@ -44,22 +46,21 @@ public static function convert2utf8($string)
{
//检测并转换编码
$encode = self::detect($string);
if($encode === false){
if ($encode === false) {
throw new Exception('detect encoding failed');
}

//转换编码
if($encode != 'UTF-8'){
$string = iconv($encode,'UTF-8//IGNORE',$string);
if ($encode != 'UTF-8') {
$string = iconv($encode, 'UTF-8//IGNORE', $string);
}

//移除utf8-bom
$string=trim($string);
if(strpos($string,self::UTF8_BOM)===0){
$string = substr($string,strlen(self::UTF8_BOM));
$string = trim($string);
if (strpos($string, UTF8_BOM) === 0) {
$string = substr($string, strlen(UTF8_BOM));
}

return $string;
}

}
}
50 changes: 33 additions & 17 deletions src/extend/shirne/common/Poster.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,31 +582,47 @@ protected function imageBorder($srcimg, $border, $bordercolor = 'ffffff', $radiu

//画四条边
imagefilledpolygon($img, [
$radius, 0,
$radius * .5 + $border, $border - 1,
$w + $border - $radius * .5, $border - 1,
$w + $border * 2 - $radius, 0
$radius,
0,
$radius * .5 + $border,
$border - 1,
$w + $border - $radius * .5,
$border - 1,
$w + $border * 2 - $radius,
0
], 4, $bcolor);

imagefilledpolygon($img, [
$w + $border * 2, $radius,
$w + $border, $border + $radius * .5,
$w + $border, $h + $border - $radius * .5,
$w + $border * 2, $h + $border * 2 - $radius
$w + $border * 2,
$radius,
$w + $border,
$border + $radius * .5,
$w + $border,
$h + $border - $radius * .5,
$w + $border * 2,
$h + $border * 2 - $radius
], 4, $bcolor);

imagefilledpolygon($img, [
$w + $border * 2 - $radius, $h + $border * 2,
$w + $border - $radius * .5, $h + $border,
$border + $radius * .5, $h + $border,
$radius, $h + $border * 2
$w + $border * 2 - $radius,
$h + $border * 2,
$w + $border - $radius * .5,
$h + $border,
$border + $radius * .5,
$h + $border,
$radius,
$h + $border * 2
], 4, $bcolor);

imagefilledpolygon($img, [
0, $h + $border * 2 - $radius,
$border - 1, $h + $border - $radius * .5,
$border - 1, $border + $radius * .5,
0, $radius
0,
$h + $border * 2 - $radius,
$border - 1,
$h + $border - $radius * .5,
$border - 1,
$border + $radius * .5,
0,
$radius
], 4, $bcolor);

if ($radius > 0) {
Expand Down Expand Up @@ -695,7 +711,7 @@ protected function parseLogo($qrimg, $logo)

public function __destruct()
{
if ($this->bg && is_resource($this->bg)) {
if ($this->bg) {
imagedestroy($this->bg);
}
}
Expand Down

0 comments on commit 7741bee

Please sign in to comment.