Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Funkcja Do Miniaturek Zdjęć
yono
post
Post #1





Grupa: Zarejestrowani
Postów: 29
Pomógł: 0
Dołączył: 20.04.2003
Skąd: Tarnów

Ostrzeżenie: (0%)
-----


Cześć pisze swój moduł-galerie do nuka. Potrzebuję skrypt a najlepiej funkcję, która wyświetla mi miniaturkę zdjęcia, której podaje jako argument scieżkę. (IMG:http://forum.php.pl/style_emoticons/default/aarambo.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
silent
post
Post #2





Grupa: Zarejestrowani
Postów: 127
Pomógł: 0
Dołączył: 18.08.2004
Skąd: Jastrzębie Zdrój

Ostrzeżenie: (0%)
-----


Jak nie ma jak jest? (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
  1. <?php
  2. function resizeImage($src,$dest,$maxWidth,$maxHeight,$quality=100) {
  3.  if (file_exists($src) && isset($dest)) {
  4.  // path info
  5.  $destInfo = pathInfo($dest);
  6.  
  7.  // image src size
  8.  $srcSize = getImageSize($src);
  9.  
  10.  // image dest size $destSize[0] = width, $destSize[1] = height
  11.  $srcRatio = $srcSize[0]/$srcSize[1]; // width/height ratio
  12.  $destRatio = $maxWidth/$maxHeight;
  13.  if ($destRatio > $srcRatio) {
  14.  $destSize[1] = $maxHeight;
  15.  $destSize[0] = $maxHeight*$srcRatio;
  16.  }
  17.  else {
  18.  $destSize[0] = $maxWidth;
  19.  $destSize[1] = $maxWidth/$srcRatio;
  20.  }
  21.  
  22.  // path rectification
  23.  if ($destInfo['extension'] == &#092;"gif\") {
  24.  $dest = substr_replace($dest, 'jpg', -3);
  25.  }
  26.  
  27.  // true color image, with anti-aliasing
  28.  $destImage = imagecreatetruecolor($destSize[0],$destSize[1]);
  29.  
  30.  // src image
  31.  switch ($srcSize[2]) {
  32.  case 1: //GIF
  33.  $srcImage = imageCreateFromGif($src);
  34.  break;
  35.  
  36.  case 2: //JPEG
  37.  $srcImage = imageCreateFromJpeg($src);
  38.  break;
  39.  
  40.  case 3: //PNG
  41.  $srcImage = imageCreateFromPng($src);
  42.  break;
  43.  
  44.  default:
  45.  return false;
  46.  break;
  47.  }
  48.  
  49.  imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
  50.  
  51.  switch ($srcSize[2]) {
  52.  case 1:
  53.  case 2:
  54.  imageJpeg($destImage,$dest,$quality);
  55.  break;
  56.  
  57.  case 3:
  58.  imagePng($destImage,$dest);
  59.  break;
  60.  }
  61.  return true;
  62.  }
  63.  else {
  64.  return false;
  65.  }
  66. }
  67. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 05:11