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