Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Изменнение размера картинок..
Форумы портала PHP.SU » PHP » Напишите за меня, пожалуйста » Изменнение размера картинок..

Страниц (1): [1]
 

1. .vp - 06 Мая, 2008 - 16:36:51 - перейти к сообщению
Кто-нибудь знает как сделать скрипт, уменьшающий размер картинки?..
нужно чтобы он не сохранял ее в отдельный файл а уменьшал прям для браузера,
впринципе как в галереях IPB,
оч нужно..
3. scuter - 09 Мая, 2008 - 20:09:25 - перейти к сообщению
PHP:
скопировать код в буфер обмена
  1. function imageresize($outfile,$infile,$neww,$newh,$quality,$type='jpg')
  2. {
  3.         if($type == 'jpg' || $type == 'jpeg')
  4.         {
  5.                 $im=imagecreatefromjpeg($infile);
  6.         }
  7.         elseif($type == 'gif')
  8.         {
  9.                 $im=imagecreatefromgif($infile);
  10.         }
  11.         elseif($type == 'png')
  12.         {
  13.                 $im=imagecreatefrompng($infile);
  14.         }
  15.         elseif($type == 'bmp')
  16.         {
  17.                 $im=imagecreatefromwbmp($infile);
  18.         }
  19.         else
  20.         {
  21.                 $im=imagecreatefromjpeg($infile);
  22.         }
  23.         $ix = imagesx($im);
  24.         $iy = imagesy($im);
  25.         $iyr = $iy*$neww;
  26.         $iyr = $iyr/$ix;
  27.         $ixr = $ix*$newh;
  28.         $ixr = $ixr/$iy;
  29.         if($iyr < $newh)
  30.         {
  31.                 $newh = $iyr;
  32.         }
  33.         else
  34.         {
  35.                 $neww = $ixr;
  36.         }
  37.         $im1=imagecreatetruecolor($neww,$newh);
  38.         imagecopyresampled($im1,$im,0,0,0,0,$neww,$newh,imagesx($im),imagesy($im));
  39.         if($type == 'jpg' || $type == 'jpeg')
  40.         {
  41.                 imagejpeg($im1,$outfile,$quality);
  42.         }
  43.         elseif($type == 'gif')
  44.         {
  45.                 imagegif($im1,$outfile,$quality);
  46.         }
  47.         elseif($type == 'png')
  48.         {
  49.                 imagepng($im1,$outfile,$quality);
  50.         }
  51.         elseif($type == 'bmp')
  52.         {
  53.                 imagewbmp($im1,$outfile,$quality);
  54.         }
  55.         else
  56.         {
  57.                 imagejpeg($im1,$outfile,$quality);
  58.         }
  59.         imagejpeg($im1,$outfile,$quality);
  60.         imagedestroy($im);
  61.         imagedestroy($im1);
  62. }

 

Powered by ExBB FM 1.0 RC1