Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] skanowanie miniaturek do rozmiaru 100px z zachowaniem skali
Vion
post
Post #1





Grupa: Zarejestrowani
Postów: 112
Pomógł: 2
Dołączył: 27.06.2008

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


Witam mam taki kod który tworzy miniaturki, ale ten kod tworzy miniaturki o 10% mniejsze od oryginalu. Co trzeba zrobic aby obrazek byl pomniejszany do 100px z zachowaniem skali? Np, jezeli obrazek bedzie mial 800x600px to miniaturka wynosi 100x75px lub jezeli obrazek ma 600x800 to wtedy wymiary wynosza 100x134px ?

  1. <?php
  2. $image_caption = $_POST['image_caption'];
  3. $image_username = $_SESSION['name'];
  4. $image_tempname = $_FILES['image_filename']['name'];
  5. $image_comment = $_POST['image_comment'];
  6. $today = date("Y-m-d");
  7.  
  8. // umieszczenie obrazu i sprawdzenie jego formatu
  9. $ImageDir ="c:/Program Files/WebServ/httpd-users/aaa/images/";
  10.  
  11.  
  12. $ImageThumb = $ImageDir . "thumbs/";
  13.  
  14.  
  15. $ImageName = $ImageDir . $image_tempname;
  16.  
  17. if (move_uploaded_file($_FILES['image_filename']['tmp_name'], 
  18. $ImageName)) {
  19.  
  20. // pobranie informacji na temat umieszczonego obrazu
  21. list($width, $height, $type, $attr) = getimagesize($ImageName);
  22.  
  23. if ($type > 3) {
  24. echo "Przykro nam, ale przesłany obraz nie jest w formacie GIF, JPG lub " .
  25.  "PNG.<br>";
  26. echo "Kliknij przycisk 'Wstecz' w przeglądarce i spróbuj ponownie.";
  27. } else {
  28.  
  29. // obraz jest w poprawnym formacie, można kontynuować
  30.  
  31. // wstawienie informacji w tabeli images
  32.  
  33. $insert = "INSERT INTO images
  34. (image_caption, image_username, image_date, image_comment)
  35. VALUES
  36. ('$image_caption', '$image_username', '$today', '$image_comment')";
  37. $insertresults = mysql_query($insert)
  38. or die(mysql_error());
  39.  
  40. $lastpicid = mysql_insert_id();
  41.  
  42. $newfilename = $ImageDir . $lastpicid . ".jpg";
  43.  
  44. if ($type == 2) {
  45. rename($ImageName, $newfilename);
  46. } else {
  47. if ($type == 1) {
  48. $image_old = imagecreatefromgif($ImageName);
  49. } elseif ($type == 3) {
  50. $image_old = imagecreatefrompng($ImageName);
  51. }
  52.  
  53. // skonwertuj obraz do formatu JPG
  54. $image_jpg = imagecreatetruecolor($width, $height);
  55. imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, 
  56.  $width, $height, $width, $height);
  57. imagejpeg($image_jpg, $newfilename);
  58. imagedestroy($image_old);
  59. imagedestroy($image_jpg);
  60. }
  61.  
  62.  
  63.  
  64. $newthumbname = $ImageThumb . $lastpicid . ".jpg";
  65.  
  66.  
  67.  
  68. // pobierz wymiary miniaturki
  69. $thumb_width = $width * 0.10;
  70. $thumb_height = $hegiht * 0.10;
  71.  
  72. // utwórz miniaturkę
  73. $largeimage = imagecreatefromjpeg($newfilename);
  74. $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
  75. imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 
  76. $thumb_width, $thumb_height, $width, $height);
  77. imagejpeg($thumb, $newthumbname);
  78. imagedestroy($largeimage);
  79. imagedestroy($thumb);
  80. ?>
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: 6.10.2025 - 13:59