The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]



Индекс форумов
Составление сообщения

Исходное сообщение
"Ресайт изображения"
Отправлено BsDr, 28-Авг-08 17:07 
>Народ, как ресайзануть из любого размера имаг в ширину 800, и высоту
>пропорционально ширине?

resizeImage ($src, $dest, $newHeight, 800)

function resizeImage ($src, $dest, $newHeight, $newWidth)
  {
    /*if ( $dest )
    {
      fopen($dest, "w") ||
        die("Can not write to $dest.  Check directory permissions!");
    }*/
    $imgInfo = getimagesize($src);
    $width = $imgInfo[0]; $height = $imgInfo[1];
    $file_type = $imgInfo[2];
    if($width <= $newWidth)
        {
            $newWidth = 0;
        }
    else
        {
            $newHeight = ($newWidth*$height)/ $width;
        }
    if ( $newHeight || $newWidth )
    {
      if ( $newHeight && $newWidth )
      {
        $width = $newWidth;
        $height = $newHeight;
      } else {
        if ( $newWidth == "0" )
        {
          $ratio = (intval(($width / $newWidth) * 100)) / 100;  
          $width = (intval(($width / $ratio) * 100)) / 100;
          $height = (intval(($height / $ratio) * 100)) / 100;
        } else {
          $ratio = (intval(($width / $newHeight) * 100)) / 100;
          $width = (intval(($width / $ratio) * 100)) / 100;
          $height = (intval(($height / $ratio) * 100)) / 100;
        }
      }
    }
    $destimg=ImageCreateTrueColor($width,$height);
    switch ($file_type)
    {
      case 1:
        $srcimg = imagecreatefromgif($src);
        if (function_exists(ImageGIF))
        {
          $imgType = "gif";
        } else {
          $imgType = "jpeg";
        }
        break;
      case 2:
        $srcimg = imagecreatefromjpeg($src);
        $imgType = "jpeg";  
        break;
      case 3:
        $srcimg = imagecreatefrompng($src);
        $imgType = "png";
        break;
      default:
        break;
    }
    ImageCopyResized($destimg,$srcimg,0,0,0,0,$width,$height,ImageSX($srcimg),ImageSY($srcimg));
    if ( !$dest ) { header ("Content-type: image/$imgType"); }
    switch ($file_type)
    {
      case 1:
        if (function_exists(ImageGIF))
        {
          if ( $dest) { imagegif ($destimg, $dest); } else { imagegif($destimg); }
        } else {
          if ( $dest) { imagejpeg ($destimg, $dest); } else { imagejpeg($destimg); }
        }
        break;
      case 2:
        if ( $dest) { imagejpeg ($destimg, $dest); } else { imagejpeg($destimg); }
        break;
      case 3:
        if ( $dest) { imagepng ($destimg, $dest); } else { imagepng($destimg); }
        break;
      default:
        break;
    }
    imagedestroy ($srcimg);
    imagedestroy ($destimg);
  }

 

Ваше сообщение
Имя*:
EMail:
Для отправки новых сообщений в текущей нити на email укажите знак ! перед адресом, например, !user@host.ru (!! - не показывать email).
Более тонкая настройка отправки ответов производится в профиле зарегистрированного участника форума.
Заголовок*:
Сообщение*:
 
При общении не допускается: неуважительное отношение к собеседнику, хамство, унизительное обращение, ненормативная лексика, переход на личности, агрессивное поведение, обесценивание собеседника, провоцирование флейма голословными и заведомо ложными заявлениями. Не отвечайте на сообщения, явно нарушающие правила - удаляются не только сами нарушения, но и все ответы на них. Лог модерирования.



Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру