За последние 24 часа нас посетил 15761 программист и 1630 роботов. Сейчас ищут 975 программистов ...

Класс для работы с картинками

Тема в разделе "Обработка изображений средствами PHP", создана пользователем klik, 19 май 2009.

  1. klik

    klik Guest

    Оцениваем класс для работы с картинками. Пишите что добавить - что поправить. (обновленно)
    --Обновление--
    *проверка на сущевствование папки
    *перевод картинки в текст
    *проблема с сохранением
    *закругленные края (только для png)
    *фото фильтры...
    *тень
    PHP:
    1.  
    2. <?php
    3. /**********************************
    4.     made by: Tatarinov Denis
    5.     version: 2.10v-nws
    6.     date relize: 18.05.2009
    7.     email: [email=denikin91@rambler.ru]denikin91@rambler.ru[/email]
    8. ***********************************/
    9.  
    10. class images {
    11.     protected $time = 0;
    12.     protected $name_file = '';
    13.     #начальные размеры изображения
    14.     protected $old_width = NULL;
    15.     protected $old_height = NULL;
    16.     #конечные размеры изображения
    17.     protected $width = NULL;
    18.     protected $height = NULL;
    19.     protected $image = false;
    20.     #качество и тип изображения
    21.     protected $quality = 100;
    22.     protected $type = false;
    23.     protected $new_type = false;
    24.     #максимальный размер (ширины или длинны) и папка для загрузки
    25.     protected $maax = 3000;
    26.     protected $dir_upload = 'upload/';
    27.     #начальный и конечный размер файла (в битах)
    28.     protected $size_img = NULL;
    29.     protected $new_size_img = NULL;
    30.     #to text
    31.     protected $table = '';
    32.     #ошибка
    33.     var $error = '';
    34.     var $error_file = '';
    35.     var $error_lng = array(
    36.                         'no_file' => "Файла не существует <br>",
    37.                         'old_file' => "Файл уже существует <br />",
    38.                         'more_size' => "Размер картинки слишком большой <br />",
    39.                         'no_type' => "Неизвесный формат <br />",
    40.                         'error_dir' => "Папки не существует или закрыта назапись <br />"
    41.                      );
    42.    
    43.    
    44.     #получаем данные о картинке...
    45.     public function info($parametr)
    46.     {
    47.         switch($parametr)
    48.         {
    49.             case 'new_width': return(round($this->width,2)); break;
    50.             case 'new_height': return(round($this->height,2)); break;          
    51.             case 'old_width': return(round($this->old_width,2)); break;
    52.             case 'old_height': return(round($this->old_height,2)); break;          
    53.             case 'type': return($this->type_img); break;           
    54.             case 'new_type': return($this->new_type); break;           
    55.             case 'size': return(round($this->size_img/1024,3)); break;         
    56.             case 'new_size': return(round($this->new_size_img/1024,3)); break;         
    57.             case 'time': return(round($this->time,2)); break;          
    58.             case 'name': return($this->name_file); break;          
    59.             case 'totext': return($this->table); break;        
    60.             default: return 'Fuck!!! не тот параметр! Смотри что пишешь в коде!!!!!'; break;
    61.         }
    62.     }
    63.    
    64.     #Установить новую директорию загрузки
    65.     public function new_dir($dir)
    66.     {
    67.         $this->dir_upload = $dir;
    68.     }
    69.     public function max($max)
    70.     {
    71.         $this->maax = $max;
    72.     }
    73.     #Открываем картинку и получаем параметры, в связи с ними создаем формы
    74.     public function load($file_name)
    75.     {
    76.         $this->name_file = $file_name;
    77.         $time_before = $this->get_time();
    78.         if(is_file($file_name))
    79.         {
    80.             list($width, $height, $type) = getimagesize($file_name);
    81.             if($width>$this->maax or $height>$this->maax)   $this->error = $this->error_lng['more_size'];
    82.             else
    83.             {
    84.                  $this->width = $width;
    85.                  $this->height = $height;                
    86.                  $this->old_width = $width;              
    87.                  $this->old_height = $height;
    88.                  $this->size_img = filesize($file_name);
    89.                  
    90.                  switch($type)
    91.                  {
    92.                      case 1:
    93.                           if($tmp_image = imagecreatefromgif($file_name)){
    94.                               $this->type = $type;                           
    95.                               $this->type_img = 'gif';
    96.                               $this->image = $tmp_image;
    97.                               imagealphablending($this->image,true);
    98.                               imagesavealpha($this->image, true);
    99.                           }
    100.                      break;
    101.                      case 2:
    102.                           if($tmp_image = imagecreatefromjpeg($file_name)){                          
    103.                               $this->type = $type;
    104.                               $this->type_img = 'jpeg';
    105.                               $this->image = $tmp_image;
    106.                           }
    107.                      break;
    108.                      case 3:
    109.                           if($tmp_image = imagecreatefromstring(file_get_contents($file_name))){
    110.                                $this->type = $type;
    111.                                $this->type_img = 'png';
    112.                                $this->image = $tmp_image;
    113.                                imagealphablending($this->image,true);
    114.                                imagesavealpha($this->image, true);
    115.                           }
    116.                      break;
    117.                      default: $this->error = $this->error_lng['no_type']; break;
    118.                  }
    119.             }
    120.         }
    121.         else $this->error = $this->error_lng['no_file'];
    122.         $this->time += $this->get_time() - $time_before;
    123.     }
    124.    
    125.     #to text
    126.     public function totext($sing='#')
    127.     {
    128.         $time_before = $this->get_time();
    129.         if(!$this->error)
    130.         {
    131.             for($i=0; $i < $this->width; $i++)
    132.             {
    133.                for ($h = 0; $h < $this->height; $h++)
    134.                {
    135.                    $rgb = imagecolorsforindex($this->image, imagecolorat($this->image, $i, $h));
    136.                    $row[$i][$h] = dechex($rgb['red']).dechex($rgb['green']).dechex($rgb['blue']);
    137.                }
    138.             }
    139.            
    140.             $this->table = "<table bgcolor='#000000' border=0 cellpadding=0 cellspacing=0 class='image'>";
    141.             for($i=0; $i < $this->height; $i++)
    142.             {
    143.                $this->table .= "<tr>";
    144.                for($h=0;$h < $this->width; $h++) $this->table .= "<td><font color=".$row[$h][$i].">".$sing."</font></td>";           
    145.                $this->table .= "</tr>";
    146.             }
    147.             $this->table .= "</table>";
    148.         }
    149.         $this->time += $this->get_time() - $time_before;
    150.     }
    151.    
    152.     #проверка на запись в папку
    153.     protected function scan_dir()
    154.     {
    155.         $file = $this->dir_upload;
    156.         if(!file_exists($file)) return false;
    157.        
    158.         elseif(is_writable($file)) return true;
    159.         else
    160.         {
    161.             @chmod($file, 0777);
    162.             if(is_writable($file)) return true;
    163.             else
    164.             {
    165.                 @chmod($file, 0755);
    166.                 if(is_writable($file)) return true;
    167.                 else return false;
    168.             }
    169.         }
    170.     }
    171.    
    172.     #обрезка картинки
    173.     public function crop($t = 0,$r = 0,$b = 0,$l = 0)
    174.     {
    175.         $time_before = $this->get_time();
    176.         if(!$this->error)
    177.         {
    178.             $new_image = imagecreatetruecolor($this->width-($l+$r), $this->height-($t+$b));
    179.             imagecopyresampled($new_image, $this->image, -$l, -$t, 0, 0, $this->width, $this->height, $this->width, $this->height);        
    180.                 $this->width =  $this->width-($l+$r);
    181.                 $this->height = $this->height-($t+$b);
    182.                 $this->image = $new_image;
    183.         }
    184.         $this->time += $this->get_time() - $time_before;
    185.     }
    186.    
    187.     #фото-фильтры
    188.     public function filter($permission = 'no')
    189.     {
    190.         $time_before = $this->get_time();
    191.         if(!$this->error)
    192.         {
    193.             if(ereg("grey",$permission)) imagefilter($this->image, IMG_FILTER_GRAYSCALE);
    194.             if(ereg("negativ",$permission)) imagefilter($this->image, IMG_FILTER_NEGATE);
    195.             if(ereg("sun",$permission))
    196.             {
    197.                 preg_match('/sun\s*=\s*(\d+)/is', $permission, $lvl);
    198.                 imagefilter($this->image, IMG_FILTER_BRIGHTNESS, $lvl[1]);
    199.             }
    200.             if(ereg("contrast",$permission))
    201.             {
    202.                 preg_match('/contrast\s*=\s*(\d+)/is',$permission, $lvl);
    203.                 imagefilter($this->image, IMG_FILTER_CONTRAST, $lvl[1]*(-1));
    204.             }
    205.             if(ereg("shadow",$permission))
    206.             {
    207.                 preg_match('/shadow\s*=\s*(\d+),\s*(\d+)?/is',$permission, $lvl);
    208.                 if(!$lvl)$this->shadow();
    209.                 else $this->shadow($lvl[1], $lvl[2]);
    210.             }
    211.             if(ereg("blur",$permission)) imagefilter($this->image, IMG_FILTER_GAUSSIAN_BLUR);
    212.         }
    213.         $this->time += $this->get_time() - $time_before;
    214.     }
    215.    
    216.     #тень
    217.     protected function shadow($width = 4, $deep = 7)
    218.     {
    219.         $iw = $this->width + 4*$width;
    220.         $ih = $this->height  + 4*$width;
    221.         $img = imagecreatetruecolor($iw, $ih);
    222.        
    223.         $deep = 255-$deep*12;
    224.         $shadow = imagecolorallocate($img, $deep, $deep, $deep);      
    225.        
    226.         $bg = imagecolorallocate($img, 255, 255, 255);
    227.         imagefilledrectangle($img,0,0,$iw,$ih,$bg);
    228.         imagefilledrectangle($img, 1+$width, 1+$width, $iw-1-$width, $ih-1-$width, $shadow);
    229.        
    230.         $matrix = array (array(1,1,1),array(1,1,1),array(1,1,1));
    231.         for ($i=0; $i < $width*2; $i++, imageconvolution($img, $matrix, 9, 0));    
    232.        
    233.         imagecopyresampled($img, $this->image, 2*$width,2*$width,0,0,$this->width,$this->height,$this->width,$this->height);
    234.         $this->image = $img;       
    235.     }
    236.    
    237.     #скругление углов
    238.     public function corner($radius = 30, $rate = 5){
    239.         $time_before = $this->get_time();
    240.         if(!$this->error)
    241.         {
    242.             if($this->type_img == 'png')
    243.             {
    244.                
    245.                 imagealphablending($this->image, false);
    246.                 imagesavealpha($this->image, true);
    247.                
    248.                 $rs_radius = $radius * $rate;              
    249.                 $corner = imagecreatetruecolor($rs_radius * 2, $rs_radius * 2);
    250.                 imagealphablending($corner, false);
    251.                
    252.                 $trans = imagecolorallocatealpha($corner, 255, 255, 255 ,127);
    253.                 imagefill($corner, 0, 0, $trans);
    254.                
    255.                 $positions = array(
    256.                     array(0, 0, 0, 0),
    257.                     array($rs_radius, 0, $this->width - $radius, 0),
    258.                     array($rs_radius, $rs_radius, $this->width - $radius, $this->height - $radius),
    259.                     array(0, $rs_radius, 0, $this->height - $radius),
    260.                 );
    261.                
    262.                 foreach ($positions as $pos) imagecopyresampled($corner, $this->image, $pos[0], $pos[1], $pos[2], $pos[3], $rs_radius, $rs_radius, $radius, $radius);
    263.                
    264.                 $i = -$rs_radius;
    265.                 $y2 = -$i;
    266.                
    267.                 for (; $i <= $y2; $i++)
    268.                 {
    269.                     $y = $i;
    270.                     $x = sqrt($rs_radius*$rs_radius - $y* $y);
    271.                     $y += $rs_radius;
    272.                     $x += $rs_radius;
    273.                     imageline($corner, $x, $y, $rs_radius * 2, $y, $trans);
    274.                     imageline($corner, 0, $y, $rs_radius * 2 - $x, $y, $trans);
    275.                 }
    276.                
    277.                 foreach ($positions as $i => $pos) imagecopyresampled($this->image, $corner, $pos[2], $pos[3], $pos[0], $pos[1], $radius, $radius, $rs_radius, $rs_radius);
    278.             }
    279.         }
    280.         $this->time += $this->get_time() - $time_before;
    281.     }
    282.    
    283.     #поворот картинки
    284.     public function rotate($ygol)
    285.     {
    286.         $time_before = $this->get_time();
    287.         if(!$this->error)
    288.         {
    289.             switch($ygol)
    290.             {
    291.                 case 'l':
    292.                 case 'left': $gs = 90; break;
    293.                 case 'r':
    294.                 case 'right': $gs = -90; break;
    295.                 default: $gs = -90; break;
    296.             }
    297.             $new_image = imagecreatetruecolor($this->width,$this->height);
    298.             $this->image = imagerotate($this->image, $gs,1);           
    299.             $this->width = imagesx($this->image);            
    300.             $this->height = imagesy($this->image);
    301.         }
    302.         $this->time += $this->get_time() - $time_before;
    303.     }
    304.    
    305.     #общая функция
    306.     public function re($size, $ge = 'none')
    307.     {
    308.         $time_before = $this->get_time();
    309.         if(!$this->error)
    310.         {
    311.             $size = ($size>$this->maax)? $this->maax : $size;
    312.             if(ereg("width|w|W", $ge)) $this->width($size);        
    313.             if(ereg("height|h|H", $ge)) $this->height($size);          
    314.             if(ereg("%", $size))
    315.             {
    316.                 $size = substr($size,0,-1);
    317.                 $size = ($size<0)? 1 : $size;
    318.                 $size = ($size>100)? 100 : $size;
    319.                 $this->percent($size);
    320.             }
    321.         }
    322.         $this->time += $this->get_time() - $time_before;
    323.     }
    324.    
    325.     #установление собственной ширины картинки
    326.     protected function width($new_width = 2)
    327.     {
    328.         $time_before = $this->get_time();
    329.         if(!$this->error)
    330.         {
    331.            $new_width = ($new_width<2)? 2 : $new_width;
    332.            $ratio = $this->width / $new_width;         
    333.            $new_height = $this->height / $ratio;
    334.            $new_image = imagecreatetruecolor($new_width, $new_height);
    335.            
    336.            if(imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, round($new_width), round($new_height), $this->width, $this->height))
    337.            {
    338.                $this->width = round($new_width);
    339.                $this->height = round($new_height);             
    340.                $this->image = $new_image;              
    341.            }
    342.            else imagedestroy($new_image);
    343.         }
    344.         $this->time += $this->get_time() - $time_before;
    345.      }
    346.      
    347.      #установление собственной высоты картинки
    348.      protected function height($new_height = 2)
    349.      {
    350.         $time_before = $this->get_time();
    351.         if(!$this->error)
    352.         {
    353.            $new_height = ($new_height<2)? 2 : $new_height;
    354.            $ratio = $this->height / $new_height;           
    355.            $new_width = $this->width / $ratio;         
    356.            $new_image = imagecreatetruecolor($new_width, $new_height);
    357.            
    358.            if( imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, round($new_width), round($new_height), $this->width, $this->height))
    359.            {
    360.                $this->width = round($new_width);
    361.                $this->height = round($new_height);
    362.                $this->image = $new_image;
    363.            }
    364.           else imagedestroy($new_image);
    365.         }
    366.         $this->time += $this->get_time() - $time_before;
    367.      }
    368.      
    369.      #Процентное уменьшение или увеличение
    370.      protected function percent($percent = 100)
    371.      {
    372.         $time_before = $this->get_time();
    373.         if(!$this->error)
    374.         {
    375.             $new_height = $this->height * ($percent/100);
    376.             $new_width = $this->width * ($percent/100);                
    377.             $new_image = imagecreatetruecolor($new_width, $new_height);
    378.            
    379.             if( imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, round($new_width), round($new_height), $this->width, $this->height))
    380.             {
    381.                $this->width = round($new_width);
    382.                $this->height = round($new_height);
    383.                $this->image = $new_image;
    384.             }
    385.             else imagedestroy($new_image);
    386.         }
    387.         $this->time += $this->get_time() - $time_before;
    388.      }
    389.      
    390.     #функция установления качества изображения
    391.     public function quality($quality = 75)
    392.     {
    393.         $time_before = $this->get_time();
    394.         if(!$this->error)
    395.         {
    396.              $quality = round($quality);
    397.              $quality = ($quality<0)? 1 : $quality;          
    398.              $quality = ($quality>100)? 100 : $quality;
    399.              $this->quality = $quality;
    400.         }
    401.         $this->time += $this->get_time() - $time_before;
    402.     }
    403.  
    404.     #функция вывода изображения
    405.     public function save($name, $replace = 'none', $format = '')
    406.     {
    407.         $time_before = $this->get_time();
    408.         if(!$this->error)
    409.         {
    410.             if($this->scan_dir())
    411.             {
    412.                 if(!$format)
    413.                 {
    414.                     $format = $this->type_img;
    415.                     $this->new_type = $this->type_img;
    416.                 } else $this->new_type = $format;
    417.                
    418.                 if(!is_file($this->dir_upload.$name.'.'.$format) or $replace == 'yes')
    419.                 {
    420.                     switch($format)
    421.                     {
    422.                         case 'png': imagepng($this->image, $this->dir_upload.$name.'.'.$format); break;
    423.                         case 'jpg':case'jpeg': imagejpeg($this->image, $this->dir_upload.$name.'.'.$format, $this->quality );break;
    424.                         case 'gif': imagegif($this->image, $this->dir_upload.$name.'.'.$format); break;
    425.                     }
    426.                     $new_image = $this->dir_upload.$name.'.'.$format;            
    427.                     $this->new_size_img = filesize($new_image);
    428.                 }
    429.                 else $this->error_file = $this->error_lng['old_file'];
    430.             }
    431.             else $this->error_file = $this->error_lng['error_dir'];
    432.         }
    433.         $this->time += $this->get_time() - $time_before;
    434.     }
    435.    
    436.     #функции времени
    437.     protected function get_time()
    438.     {
    439.         list($seconds, $microSeconds) = explode(' ', microtime());
    440.         return ((float)$seconds + (float)$microSeconds);
    441.     }  
    442.    
    443.     #очистка памяти
    444.     public function destroy()
    445.     {
    446.         if(!$this->error)
    447.         {
    448.             if($this->image)  imagedestroy($this->image);
    449.             $this->old_height = NULL;          
    450.             $this->old_width = NULL;
    451.             $this->height = NULL;
    452.             $this->width = NULL;
    453.             $this->type = false;
    454.             $this->size_img = NULL;
    455.             $this->new_size_img = NULL;
    456.             $this->time = 0;
    457.         }
    458.     }
    459. }
    460. ?>
    461.  

    /*******************************************************/
    Пример использования...

    PHP:
    1.  
    2. <html>
    3. <body >
    4. <?php
    5. define('MAIN_DIR',dirname(__FILE__));
    6. include_once MAIN_DIR.('/images.class.php');
    7. $img = new images; //включаем класс
    8.  
    9.     $name = 'vista_1'; // конечное изображение (название)
    10.     //$img->max(3400); //до загрузки картинки устанавливаем максимальное значение ширины или высоты для обработки и входа, иначе он заругается (по умолчанию 3000)
    11.     //$img->new_dir('upload/'); // папка для загрузки
    12.     $img->load('images/vista_1.jpg'); // выбираем картинку
    13.     //$img->quality(75); // устанавливаем качество, по умолчанию 100
    14.     //$img->re('100%'); // изменение высоты и длинны в процентах
    15.     //$img->re(650, 'width'); // изменение только ширины, пропорционально
    16.     //$img->re(200, 'height'); // изменение только высоты, пропорционально
    17.     //$img->crop(20,20,20,20); // обрезка (верх, право, низ, лево) по часовой стрелке
    18.     //$img->rotate('right'); // поворот вправо
    19.     //$img->rotate('left'); //поворот влево
    20.     $img->filter('shadow=4,10 grey blur sun = 10 contrast = 10'); // Применение фото-фильтров
    21.                                                             // shadow - ширина, сила (4,7 - красиво и по умолчанию)
    22.                                                             // grey - обесцвечивание без параметров
    23.                                                             // blur - размытие без параметров
    24.                                                             // sun - яркость = !сила
    25.                                                             // contrast - контраст = !сила
    26.                                                            
    27.     $img->corner(50); // скругленные углы только если формат файла png
    28.     //$img->totext('*'); // вывести картинку символами. Указывать символ, которым выводить, жутко тормозит при размерах выше 150*100
    29.     $img->save($name, 'yes');// сохраняем картинку  под именем $name,
    30.                                     //второй параметр - заменять, если поставишь yes то выведет ошибку если картинка уже существует
    31.                                     //третий необязательный  параметр - формат вывода, если не указан выведет в том, который  есть
    32.    
    33.     if(!$img->error)
    34.     {
    35.         echo '<img src="upload/'.$name.'.'.$img->info('new_type').'" width="'.$img->info('new_width').'" height="'.$img->info('new_height').'"><br>'
    36.         //выводим картинку в папку которую сохраняли, с типом который определен
    37.             .'<font color="red">'.$img->error_file.'<br></font>'
    38.             //.$img->info('totext').'<br><br>'
    39.             .$img->info('old_width').' px - начальная ширина <br>'
    40.             .$img->info('old_height').' px - начальная высота <br>'
    41.             .$img->info('new_width').' px - новая ширина <br>'
    42.             .$img->info('new_height').' px - новая длинна <br>'
    43.             .$img->info('size').' kb - начальный размер <br>'
    44.             .$img->info('new_size').' kb - новый размер <br>'
    45.             .$img->info('type').' - изночальный тип <br>'
    46.             .$img->info('new_type').' - конечный тип <br>'
    47.             .$img->info('time').' секунд - затраченное время <br>';
    48.     }
    49.     else echo'<font color="red">'.$name.$img->error.'</font>';
    50.    
    51.     $img->destroy(); // очистка памяти
    52.  
    53. ?>
    54. </body>
    55. </html>
    56.  
    /*****************************************************************************/

    Был вдохновлен статьей и классом http://www.php.ru/forum/viewtopic.php?t=8807
    Убрал то, что не нужно, и добавил немного своего!

    Нету работы с текстом. Мне не нужна!
    Есть к нему дополнение для работы с водяными знаками.

    Если актуально - пишите, по мере дополнения буду добавлять свежие версии.
     
  2. Apple

    Apple Активный пользователь

    С нами с:
    13 янв 2007
    Сообщения:
    4.984
    Симпатии:
    2
    Столько грамматических ошибок свет с рождения не видовал.
     
  3. andrey_94

    andrey_94 Активный пользователь

    С нами с:
    17 май 2009
    Сообщения:
    40
    Симпатии:
    0
    а как этот класс использовать. т.е к чему подключать?
     
  4. klik

    klik Guest

    Смотря какие у вас цели!
    Там пример использования показан!
     
  5. Mr.M.I.T.

    Mr.M.I.T. Старожил

    С нами с:
    28 янв 2008
    Сообщения:
    4.586
    Симпатии:
    1
    Адрес:
    у тебя канфетка?
    все ereg переписать на preg_* или strpos
     
  6. Koc

    Koc Активный пользователь

    С нами с:
    3 мар 2008
    Сообщения:
    2.253
    Симпатии:
    0
    Адрес:
    \Ukraine\Dnepropetrovsk
    klik
    прикольно.
    это типа FineReader?
     
  7. klik

    klik Guest

    Это типо проходится циклом по картинке, получает цвет каждого пикселя, и рисует символ таким же цветом

    В чем разница?
     
  8. fanta

    fanta Активный пользователь

    С нами с:
    19 апр 2007
    Сообщения:
    53
    Симпатии:
    0
    устарела)
     
  9. klik

    klik Guest

    Не ну ни ппц!?
     
  10. Inoi

    Inoi Активный пользователь

    С нами с:
    4 авг 2008
    Сообщения:
    52
    Симпатии:
    0
    Адрес:
    Волгоград
    Код (Text):
    1. $img->load('значение'); // выбираем картинку
    почему в качестве значения нельзя использовать переменную?
     
  11. Apple

    Apple Активный пользователь

    С нами с:
    13 янв 2007
    Сообщения:
    4.984
    Симпатии:
    2
    o_O
     
  12. Inoi

    Inoi Активный пользователь

    С нами с:
    4 авг 2008
    Сообщения:
    52
    Симпатии:
    0
    Адрес:
    Волгоград
    Что О.о?
    например вот так:
    Код (Text):
    1. $img->load('./foto/album/temp/'.$foto.'');
    и
    Код (Text):
    1. $img->load($foto);
    не работает, не находит картинки
     
  13. Inoi

    Inoi Активный пользователь

    С нами с:
    4 авг 2008
    Сообщения:
    52
    Симпатии:
    0
    Адрес:
    Волгоград
    ЗЫ Пути правильно.
    ЗЫЫ Если написать например
    Код (Text):
    1. $img->load('./foto/album/temp/123.jpg');
    то всё отлично
     
  14. Apple

    Apple Активный пользователь

    С нами с:
    13 янв 2007
    Сообщения:
    4.984
    Симпатии:
    2
    Перечитайте внимательно сами то, что написали.
    Внимательно!
    А потом заявляйте такие смелые фразы, окей?
     
  15. Inoi

    Inoi Активный пользователь

    С нами с:
    4 авг 2008
    Сообщения:
    52
    Симпатии:
    0
    Адрес:
    Волгоград
    Извените не вижу ошибки, что здесь не так?
     
  16. Apple

    Apple Активный пользователь

    С нами с:
    13 янв 2007
    Сообщения:
    4.984
    Симпатии:
    2
    Посмотрите внимааательно.

    Ладно, разберем в деталях:

    $img->load('./foto/album/temp/'.$foto.'');
    $img->load($foto);

    Разницу видите?
    Что содержит переменная $photo?
    123.jpg?
    А где путь?
    Невнимательность убьёт людей быстрее, чем холестирин.
     
  17. Inoi

    Inoi Активный пользователь

    С нами с:
    4 авг 2008
    Сообщения:
    52
    Симпатии:
    0
    Адрес:
    Волгоград
    Хм, а в 1 случае, что тогда не так? почему скрипт не находит картинку?
     
  18. Apple

    Apple Активный пользователь

    С нами с:
    13 янв 2007
    Сообщения:
    4.984
    Симпатии:
    2
    Да потому что пути не совпадают.
    Выведите путь на экран:

    <?

    echo $photo;

    ?>

    Ну не будет такого файла, даже с браузера его не найдет его.
    Путь надо писать в переменную тогда уж.
     
  19. Inoi

    Inoi Активный пользователь

    С нами с:
    4 авг 2008
    Сообщения:
    52
    Симпатии:
    0
    Адрес:
    Волгоград
    Так давай по порядку, если выводить перемунную
    Код (Text):
    1. echo $foto;
    тогда нормально выводится названиефото.раширениеэого фото, если забивать в переменную весь путь, то это тоже самое, неработает и всё.

    даже если писать
    Код (Text):
    1. echo "<img src=./foto/album/temp/".$foto.">";
    то фото которое должно, оно отображается, а ты говориш даже с браузера его не найду..
     
  20. Shadow_exe

    Shadow_exe Активный пользователь

    С нами с:
    28 июл 2009
    Сообщения:
    45
    Симпатии:
    0
    Передавай полный путь, а не относительный.
    Вполне возможно что скрипт вызываемый метод класса лежит в одной дериктории, а сам класс лежит в другой, поэтому локальный путь к файлу (начинающийся с точки ".") не потходит.