Разрешение на - в названии файла
This commit is contained in:
parent
6173eb4892
commit
958033a057
3 changed files with 75 additions and 76 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Tools_Image
|
class Tools_Image
|
||||||
{
|
{
|
||||||
static function load($uri)
|
static function load($uri)
|
||||||
{
|
{
|
||||||
$e = strtolower(pathinfo($uri, PATHINFO_EXTENSION));
|
$e = strtolower(pathinfo($uri, PATHINFO_EXTENSION));
|
||||||
|
|
@ -10,17 +10,17 @@ class Tools_Image
|
||||||
case 'jpeg': case 'jpg': return imagecreatefromjpeg($uri);
|
case 'jpeg': case 'jpg': return imagecreatefromjpeg($uri);
|
||||||
case 'gif': return imagecreatefromgif($uri);
|
case 'gif': return imagecreatefromgif($uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static function fit($image, $prewidth, $preheight, $force = true)
|
static function fit($image, $prewidth, $preheight, $force = true)
|
||||||
{
|
{
|
||||||
$width = imagesx($image);
|
$width = imagesx($image);
|
||||||
$height = imagesy($image);
|
$height = imagesy($image);
|
||||||
$percent = min($prewidth / $width, $preheight / $height);
|
$percent = min($prewidth / $width, $preheight / $height);
|
||||||
if ($percent > 1 && !$force) $percent = 1;
|
if ($percent > 1 && !$force) $percent = 1;
|
||||||
$new_width = $width * $percent;
|
$new_width = $width * $percent;
|
||||||
$new_height = $height * $percent;
|
$new_height = $height * $percent;
|
||||||
|
|
||||||
|
|
||||||
$image_p = imagecreatetruecolor($new_width, $new_height);
|
$image_p = imagecreatetruecolor($new_width, $new_height);
|
||||||
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
||||||
|
|
@ -36,4 +36,4 @@ class Tools_Image
|
||||||
case 'gif': imagegif($image, $uri); break;
|
case 'gif': imagegif($image, $uri); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,55 +4,55 @@ class Tools_String {
|
||||||
|
|
||||||
// from creole
|
// from creole
|
||||||
static function strToArray($str) {
|
static function strToArray($str) {
|
||||||
$str = substr($str, 1, -1); // remove { }
|
$str = substr($str, 1, -1); // remove { }
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
$subarr = array();
|
$subarr = array();
|
||||||
$in_subarr = 0;
|
$in_subarr = 0;
|
||||||
|
|
||||||
$toks = explode(',', $str);
|
$toks = explode(',', $str);
|
||||||
foreach($toks as $tok) {
|
foreach($toks as $tok) {
|
||||||
if ($in_subarr > 0) { // already in sub-array?
|
if ($in_subarr > 0) { // already in sub-array?
|
||||||
$subarr[$in_subarr][] = $tok;
|
$subarr[$in_subarr][] = $tok;
|
||||||
if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component
|
if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component
|
||||||
$res[] = static::strToArray(implode(',', $subarr[$in_subarr]));
|
$res[] = static::strToArray(implode(',', $subarr[$in_subarr]));
|
||||||
$in_subarr--;
|
$in_subarr--;
|
||||||
}
|
}
|
||||||
} elseif ($tok[0] === '{') { // we're inside a new sub-array
|
} elseif ($tok[0] === '{') { // we're inside a new sub-array
|
||||||
if ('}' !== substr($tok, -1, 1)) {
|
if ('}' !== substr($tok, -1, 1)) {
|
||||||
$in_subarr++;
|
$in_subarr++;
|
||||||
// if sub-array has more than one element
|
// if sub-array has more than one element
|
||||||
$subarr[$in_subarr] = array();
|
$subarr[$in_subarr] = array();
|
||||||
$subarr[$in_subarr][] = $tok;
|
$subarr[$in_subarr][] = $tok;
|
||||||
} else {
|
} else {
|
||||||
$res[] = static::strToArray($tok);
|
$res[] = static::strToArray($tok);
|
||||||
}
|
}
|
||||||
} else { // not sub-array
|
} else { // not sub-array
|
||||||
$val = trim($tok, '"'); // remove " (surrounding strings)
|
$val = trim($tok, '"'); // remove " (surrounding strings)
|
||||||
// perform type castng here?
|
// perform type castng here?
|
||||||
$res[] = $val;
|
$res[] = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Нормализация строк на русском
|
//Нормализация строк на русском
|
||||||
static function normalizeRussian($str) {
|
static function normalizeRussian($str) {
|
||||||
$result = preg_replace('/\s+/',' ', $str);
|
$result = preg_replace('/\s+/',' ', $str);
|
||||||
if (is_string($result)) {
|
if (is_string($result)) {
|
||||||
$result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям
|
$result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям
|
||||||
$result = mb_strtolower($result);
|
$result = mb_strtolower($result);
|
||||||
$result = preg_replace('/ё/','е', $str); //е на ё
|
$result = preg_replace('/ё/','е', $str); //е на ё
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Проверка равенства двух строк на русском языке.
|
//Проверка равенства двух строк на русском языке.
|
||||||
static function equalRussianCheck($str1,$str2) {
|
static function equalRussianCheck($str1,$str2) {
|
||||||
return self::normalizeRussian($str1) == self::normalizeRussian($str2);
|
return self::normalizeRussian($str1) == self::normalizeRussian($str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Попадает ли строка в список вариантов
|
* Попадает ли строка в список вариантов
|
||||||
|
|
@ -60,7 +60,7 @@ class Tools_String {
|
||||||
* output: true
|
* output: true
|
||||||
* input: $str="foo" $variants="foo1|foo2|foo3"
|
* input: $str="foo" $variants="foo1|foo2|foo3"
|
||||||
* output: false
|
* output: false
|
||||||
*/
|
*/
|
||||||
static function compare_string_to_variants($str, $variants){
|
static function compare_string_to_variants($str, $variants){
|
||||||
$variants_array = explode('|', $variants);
|
$variants_array = explode('|', $variants);
|
||||||
$founded = false;
|
$founded = false;
|
||||||
|
|
@ -69,17 +69,17 @@ class Tools_String {
|
||||||
}
|
}
|
||||||
return $founded;
|
return $founded;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function mb_str_split($str) {
|
static function mb_str_split($str) {
|
||||||
return preg_split('~~u', $str, null, PREG_SPLIT_NO_EMPTY);
|
return preg_split('~~u', $str, null, PREG_SPLIT_NO_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function mb_strtr($str, $from, $to) {
|
static function mb_strtr($str, $from, $to) {
|
||||||
return str_replace(self::mb_str_split($from), self::mb_str_split($to), $str);
|
return str_replace(self::mb_str_split($from), self::mb_str_split($to), $str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function encodestring($st) {
|
static function encodestring($st) {
|
||||||
$st = self::mb_strtr($st,"абвгдеёзийклмнопрстуфхъыэ !+-()", "abvgdeeziyklmnoprstufh_ie______");
|
$st = self::mb_strtr($st,"абвгдеёзийклмнопрстуфхъыэ !+()", "abvgdeeziyklmnoprstufh_ie_____");
|
||||||
$st = self::mb_strtr($st,"АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ", "ABVGDEEZIYKLMNOPRSTUFH_IE");
|
$st = self::mb_strtr($st,"АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ", "ABVGDEEZIYKLMNOPRSTUFH_IE");
|
||||||
$st = strtr($st, array(
|
$st = strtr($st, array(
|
||||||
" " => '_',
|
" " => '_',
|
||||||
|
|
@ -94,8 +94,8 @@ class Tools_String {
|
||||||
"#" => '_',
|
"#" => '_',
|
||||||
"*" => '_',
|
"*" => '_',
|
||||||
"ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh",
|
"ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh",
|
||||||
"щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya",
|
"щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya",
|
||||||
"Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
|
"Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
|
||||||
"Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA",
|
"Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA",
|
||||||
"Й"=>"i", "й"=>"ie", "ё"=>"Ye",
|
"Й"=>"i", "й"=>"ie", "ё"=>"Ye",
|
||||||
"№"=>"N"
|
"№"=>"N"
|
||||||
|
|
@ -107,4 +107,4 @@ class Tools_String {
|
||||||
$enc_st = self::encodestring($st);
|
$enc_st = self::encodestring($st);
|
||||||
return preg_match('/^[\w_-]+(\.[\w_-]+)?$/', $enc_st);
|
return preg_match('/^[\w_-]+(\.[\w_-]+)?$/', $enc_st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,14 +7,14 @@ class Tools_TemplateImage
|
||||||
{
|
{
|
||||||
static $listfiles = array('jpg' => 'jpeg', 'gif' => 'gif', 'png' => 'png', 'bmp' => 'wbmp');
|
static $listfiles = array('jpg' => 'jpeg', 'gif' => 'gif', 'png' => 'png', 'bmp' => 'wbmp');
|
||||||
static $listfonts = array(
|
static $listfonts = array(
|
||||||
'georgia' => 'georgia.ttf',
|
'georgia' => 'georgia.ttf',
|
||||||
'georgiabd' => 'georgiab.ttf',
|
'georgiabd' => 'georgiab.ttf',
|
||||||
'georgiaz' => 'georgiaz.ttf',
|
'georgiaz' => 'georgiaz.ttf',
|
||||||
'times' => 'times.ttf',
|
'times' => 'times.ttf',
|
||||||
'timesbd' => 'timesbd.ttf',
|
'timesbd' => 'timesbd.ttf',
|
||||||
'arial' => 'arial.ttf',
|
'arial' => 'arial.ttf',
|
||||||
'arialbd' => 'arialbd.ttf',
|
'arialbd' => 'arialbd.ttf',
|
||||||
'tahoma' => 'tahoma.ttf',
|
'tahoma' => 'tahoma.ttf',
|
||||||
'calibri' => 'calibri.ttf',
|
'calibri' => 'calibri.ttf',
|
||||||
'calibribd' => 'calibrib.ttf',
|
'calibribd' => 'calibrib.ttf',
|
||||||
'calibrii' => 'calibrii.ttf',
|
'calibrii' => 'calibrii.ttf',
|
||||||
|
|
@ -59,14 +59,14 @@ class Tools_TemplateImage
|
||||||
/**
|
/**
|
||||||
* Путь у шрифтам
|
* Путь у шрифтам
|
||||||
*/
|
*/
|
||||||
function fontPath($path)
|
function fontPath($path)
|
||||||
{
|
{
|
||||||
assert(is_string($path));
|
assert(is_string($path));
|
||||||
|
|
||||||
$this->base = $path;
|
$this->base = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
function set($name, $value)
|
function set($name, $value)
|
||||||
{
|
{
|
||||||
assert(is_string($name));
|
assert(is_string($name));
|
||||||
|
|
||||||
|
|
@ -87,11 +87,11 @@ class Tools_TemplateImage
|
||||||
/**
|
/**
|
||||||
* Создает изображение из файла
|
* Создает изображение из файла
|
||||||
*/
|
*/
|
||||||
function imagefromfile($file)
|
function imagefromfile($file)
|
||||||
{
|
{
|
||||||
assert(is_string($file));
|
assert(is_string($file));
|
||||||
|
|
||||||
$suffix = pathinfo($file, PATHINFO_EXTENSION);
|
$suffix = pathinfo($file, PATHINFO_EXTENSION);
|
||||||
if (array_key_exists($suffix, self::$listfiles)) {
|
if (array_key_exists($suffix, self::$listfiles)) {
|
||||||
return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file);
|
return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file);
|
||||||
}
|
}
|
||||||
|
|
@ -99,12 +99,12 @@ class Tools_TemplateImage
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFontFile($name)
|
function getFontFile($name)
|
||||||
{
|
{
|
||||||
assert(is_string($name));
|
assert(is_string($name));
|
||||||
|
|
||||||
if(array_key_exists(strtolower($name), self::$listfonts)) {
|
if(array_key_exists(strtolower($name), self::$listfonts)) {
|
||||||
return $this->base . self::$listfonts[$name];
|
return $this->base . self::$listfonts[$name];
|
||||||
}
|
}
|
||||||
return $this->base . 'arial.ttf';
|
return $this->base . 'arial.ttf';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,23 +127,23 @@ class Tools_TemplateImage
|
||||||
$fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle));
|
$fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle));
|
||||||
|
|
||||||
$color = intval(substr($value->color, 1), 16);
|
$color = intval(substr($value->color, 1), 16);
|
||||||
if ($value->align[0]) {
|
if ($value->align[0]) {
|
||||||
$align = Tools_Drawing::ALIGN_LEFT;
|
$align = Tools_Drawing::ALIGN_LEFT;
|
||||||
} elseif ($value->align[2]) {
|
} elseif ($value->align[2]) {
|
||||||
$align = Tools_Drawing::ALIGN_RIGHT;
|
$align = Tools_Drawing::ALIGN_RIGHT;
|
||||||
} else {
|
} else {
|
||||||
$align = Tools_Drawing::ALIGN_CENTER;
|
$align = Tools_Drawing::ALIGN_CENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value->valign[0]) {
|
if ($value->valign[0]) {
|
||||||
$valign = Tools_Drawing::ALIGN_TOP;
|
$valign = Tools_Drawing::ALIGN_TOP;
|
||||||
} elseif ($value->valign[1]) {
|
} elseif ($value->valign[1]) {
|
||||||
$valign = Tools_Drawing::ALIGN_CENTER;
|
$valign = Tools_Drawing::ALIGN_CENTER;
|
||||||
} else {
|
} else {
|
||||||
$valign = Tools_Drawing::ALIGN_BOTTOM;
|
$valign = Tools_Drawing::ALIGN_BOTTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tools_Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
|
Tools_Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
|
||||||
$value->width, $value->height,
|
$value->width, $value->height,
|
||||||
$align, $valign);
|
$align, $valign);
|
||||||
}
|
}
|
||||||
|
|
@ -158,8 +158,8 @@ class Tools_TemplateImage
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSize($new_width, $new_height)
|
function setSize($new_width, $new_height)
|
||||||
{
|
{
|
||||||
$width = imagesx($this->image);
|
$width = imagesx($this->image);
|
||||||
$height = imagesy($this->image);
|
$height = imagesy($this->image);
|
||||||
if($new_height == false) {
|
if($new_height == false) {
|
||||||
$new_height = ceil($height * $new_width / $width);
|
$new_height = ceil($height * $new_width / $width);
|
||||||
|
|
@ -170,7 +170,7 @@ class Tools_TemplateImage
|
||||||
imagecopyresampled($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
imagecopyresampled($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
||||||
// imagecopyresized($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
// imagecopyresized($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
||||||
$this->image = $image_p;
|
$this->image = $image_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare() {
|
function prepare() {
|
||||||
if($this->prepare) {
|
if($this->prepare) {
|
||||||
|
|
@ -201,4 +201,3 @@ class Tools_TemplateImage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue