slideshow.inc.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * @author Patrick Cool
  20. * @package dokeos.document
  21. * @todo convert comments to be understandable to phpDocumentor
  22. ==============================================================================
  23. */
  24. /*
  25. ==============================================================================
  26. Developped by Patrick Cool
  27. patrick.cool@UGent.be
  28. Ghent University
  29. Mai 2004
  30. http://icto.UGent.be
  31. Please bear in mind that this is only an alpha release.
  32. I wrote this quite quick and didn't think too much about it in advance.
  33. It is not perfect at all but it is workable and usefull (I think)
  34. Do not consider this as a powerpoint replacement, although it has
  35. the same starting point.
  36. ==============================================================================
  37. */
  38. /*
  39. ==============================================================================
  40. Description:
  41. This is a plugin for the documents tool. It looks for .jpg, .jpeg, .gif, .png
  42. files (since these are the files that can be viewed in a browser) and creates
  43. a slideshow with it by allowing to go to the next/previous image.
  44. You can also have a quick overview (thumbnail view) of all the images in
  45. that particular folder.
  46. Maybe it is important to notice that each slideshow is folder based. Only
  47. the images of the chosen folder are shown.
  48. This file has two large sections.
  49. 1. code that belongs in document.php, but to avoid clutter I put the code here
  50. 2. the function resize_image that handles the image resizing
  51. ==============================================================================
  52. */
  53. // ====================================================================================================
  54. // function resize_image($image, $target_width, $target_height, $slideshow=0)
  55. // ====================================================================================================
  56. // this functions calculates the resized width and resized heigt according to the source and target widths
  57. // and heights, height so that no distortions occur
  58. // parameters
  59. // $image = the absolute path to the image
  60. // $target_width = how large do you want your resized image
  61. // $target_height = how large do you want your resized image
  62. // $slideshow (default=0) = indicates weither we are generating images for a slideshow or not, t
  63. // this overrides the $_SESSION["image_resizing"] a bit so that a thumbnail
  64. // view is also possible when you choose not to resize the source images
  65. function resize_image($image, $target_width, $target_height, $slideshow=0)
  66. {
  67. // 1. grabbing the image height and width of the original image
  68. $image_properties=getimagesize($image);
  69. $source_width=$image_properties["0"];
  70. $source_height=$image_properties["1"];
  71. //print_r($image_properties);
  72. // 2. calculate the resize factor
  73. if ($_SESSION["image_resizing"]=="resizing" or $slideshow==1)
  74. {
  75. $resize_factor_width=$target_width/$source_width;
  76. $resize_factor_height=$target_height/$source_height;
  77. //echo $resize_factor_width."//".$resize_factor_height."<br>";
  78. } // if ($_SESSION["image_resizing"]=="resizing")
  79. // 4. calculate the resulting heigt and width
  80. if ($_SESSION["image_resizing"]=="resizing" or $slideshow==1)
  81. {
  82. if ($resize_factor_width<=1 and $resize_factor_height<=1)
  83. {
  84. if ($resize_factor_width > $resize_factor_height)
  85. {
  86. $image_width=$target_width;
  87. $image_height=ceil($source_height*$resize_factor_width);
  88. }
  89. if ($resize_factor_width < $resize_factor_height)
  90. {
  91. $image_width=ceil($source_width*$resize_factor_height);
  92. $image_height=$target_height;
  93. }
  94. else // both resize factors are equal
  95. {
  96. $image_width=ceil($source_width*$resize_factor_width);
  97. $image_height=ceil($source_height*$resize_factor_height);
  98. }
  99. //echo "image width=".$image_width."<br>";
  100. //echo "image height=".$image_height;
  101. } //if ($resize_factor_width<=1 and $resize_factor_height<=1)
  102. else // no resizing required
  103. {
  104. $image_width=$source_width;
  105. $image_height=$source_height;
  106. }
  107. } //if ($_SESSION["image_resizing"]=="resizing")
  108. // storing the resulting height and width in an array and returning it
  109. $image_height_width[]=$image_height;
  110. $image_height_width[]=$image_width;
  111. return $image_height_width;
  112. }
  113. ?>