Witam. Szukałem odpowiedzi na mój problem m.in tu: http://forum.gmclan.org/index.php?showtopic=1745 , jednak nie znam się na tyle na PHP, żeby rozwiązanie przekształcić do mojego trochę bardziej złożonego tematu. Otóż w skrócie, mam skrypt adaptujący rozmiar i format obrazka do możliwości danego urządzenia mobilnego i chciałbym, żeby owe powstałe wymiary zostały wpisane do znaczników width="" oraz height="" elementu <img /> w HTML.
Skrócony HTML:
  1. <?php
  2. header("Content-type: application/xhtml+xml");
  3. echo '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
  4.  
  5. include('D:/Apache Server/htdocs/ia/imageAdaptation.php');
  6. $i='gfx/img_mech.jpg';
  7. $imgurl=convertImage($i);
  8.  
  9. $imageDimensionWidth=setImageDimension();
  10. ?>
  11. <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
  12. <html xmlns="http://www.w3.org/1999/xhtml">
  13. <head>
  14. <title></title>
  15. </head>
  16. <body>
  17. <div id="pojemnik">
  18. <div id="srodek">
  19. <img class="obrazek" src="<?php echo $imgurl; ?>" alt="" <?php echo 'width="' . $imageDimensionWidth . '" height="' . $imageDimensionHeight . '"' ?> />
  20. </div>
  21. </div>
  22. </body>
  23. </html>

Z inlude'owanego pliku imageAdaptation.php, który służy do transcodowania obrazków, chciałbym zmeinne $imageDimensionWidth oraz $imageDimension Height, które znajdują się w zwracanej tablicy $dimensionArray przez funkcję setImageDimension.
Kody funkcji setImageDimension:
  1. function setImageDimension($imageWidth,$imageHeight,$deviceWidth,$deviceHeight)
  2. {
  3. $imageAspect=$imageWidth/$imageHeight;
  4. $deviceAspect=$deviceWidth/$deviceHeight;
  5. $imageAspectRatio=$imageAspect;
  6.  
  7. if (($imageWidth>$deviceWidth)&&($imageHeight>$deviceHeight))// Image larger than the screen
  8. {
  9. if (($imageAspect< 1) && ($deviceAspect< 1)) // both case Height is bigger than the width
  10. {
  11. $device2imageratio=$deviceHeight/$imageHeight;
  12. $imageDimensionHeight=(integer)($imageHeight*$device2imageratio);
  13. $imageDimensionWidth=(integer) ($imageDimensionHeight*$imageAspectRatio);
  14. }
  15. else if (($imageAspect > 1) && ($deviceAspect > 1)) // both case Width is bigger than the width
  16. {
  17. $device2imageratio=$deviceWidth/$imageWidth;
  18. $imageDimensionWidth=(integer)($imageWidth*$device2imageratio);
  19. $imageDimensionHeight=(integer) ($imageDimensionWidth/$imageAspectRatio);
  20. }
  21. else if (($imageAspect < 1) && ($deviceAspect > 1)) // So fit to Height
  22. {
  23. $device2imageratio=$deviceHeight/$imageHeight;
  24. $imageDimensionHeight=(integer)($imageHeight*$device2imageratio);
  25. $imageDimensionWidth=(integer) ($imageDimensionHeight*$imageAspectRatio);
  26. }
  27. else if (($imageAspect > 1) && ($deviceAspect< 1)) // So fit to Width
  28. {
  29. $device2imageratio=$deviceWidth/$imageWidth;
  30. $imageDimensionWidth=(integer)($imageWidth*$device2imageratio);
  31. $imageDimensionHeight=(integer) ($imageDimensionWidth/$imageAspectRatio);
  32. }
  33. else // Fit to anything
  34. {
  35. $device2imageratio=$deviceWidth/$imageWidth;
  36. $imageDimensionWidth=(integer)($imageWidth*$device2imageratio);
  37. $imageDimensionHeight=(integer) ($imageDimensionWidth/$imageAspectRatio);
  38. }
  39. }
  40. else if (($imageWidth< $deviceWidth)&&($imageHeight < $deviceHeight)) // Image smaller than the screen
  41. {
  42. $imageDimensionHeight=$imageHeight;
  43. $imageDimensionWidth=$imageWidth;
  44. }
  45. else // Any one portion of the image is outside the screen
  46. {
  47. if ($imageWidth> $deviceWidth) // So fit width
  48. {
  49. $device2imageratio=$deviceWidth/$imageWidth;
  50. $imageDimensionWidth=(integer)($imageWidth*$device2imageratio*0.9); //dopisane
  51. $imageDimensionHeight=(integer) ($imageDimensionWidth/$imageAspectRatio);
  52. }
  53. else // So fit Height
  54. {
  55. $device2imageratio=$deviceHeight/$imageHeight;
  56. $imageDimensionHeight=(integer)($imageHeight*$device2imageratio);
  57. $imageDimensionWidth=(integer) ($imageDimensionHeight*$imageAspectRatio);
  58. }
  59.  
  60. }
  61. $dimensionArray=array ($imageDimensionWidth,$imageDimensionHeight);
  62. $widthError=0;
  63. $heightError=0;
  64.  
  65. if($deviceWidth< $imageDimensionWidth)
  66. {
  67. $widthError=1;
  68. }
  69.  
  70. if($deviceHeight< $imageDimensionHeight){
  71. $heightError=1;
  72. }
  73. return $dimensionArray;
  74. }

Problem jest w tym, że funkcja ta posiada 4 parametry i nie mam pojęcia jak w pliku HTML wywołać tą funkcję, bo jej parametry są zależne od innych funkcji, wyciągnąć i oddzielić $imageDimensionWidth i $imageDimensionHeight z $dimensionArray.
Pełny kod skryptu można pobrać z:
http://www.iwanowicz.home.pl/upload/imageAdaptation.zip
Dziękuję z góry za cenne wskazówki.