SlideShow en ActionScript
0001 <? 0002 // ----------------------- 0003 // buildgallery.php 0004 // ----------------------- 0005 // by: 0006 // Mario - mariohm@fibertel.com.ar 0007 // Mike Peck - www.mikecpeck.com 0008 // Mike Johnson - mike@solanosystems.com 0009 // Christian Machmeier - www.redsplash.de 0010 // Airtight - www.airtightinteractive.com 0011 // 0012 // DESCRIPTION 0013 // ----------------------- 0014 // This script automatically generates the XML document and thumbnails for SimpleViewer 0015 // www.airtightinteractive.com/simpleviewer/ 0016 // 0017 // TO USE 0018 // ----------------------- 0019 // Instructions are at: www.airtightinteractive.com/simpleviewer/auto_instructions.html 0020 // 0021 0022 //Script modifié par rapport à mes besoins. 0023 0024 0025 function buildXML(){ 0026 if(!isset($options)) 0027 $options=""; 0028 0029 $options .= '<CHARLIESGALLERY>'; 0030 0031 $imagePath = "images/"; 0032 // Set showDownloadLinks to true if you want to show a 'Download Image' link as the caption to each image. 0033 $showDownloadLinks = false; 0034 0035 // set useCopyResized to true if thumbnails are not being created. 0036 // This can be due to the imagecopyresampled function being disabled on some servers 0037 if(!isset($useCopyResized)) 0038 $useCopyResized = false; 0039 0040 // Set sortImagesByDate to true to sort by date. Otherwise files are sorted by filename. 0041 $sortImagesByDate = true; 0042 0043 // Set sortInReverseOrder to true to sort images in reverse order. 0044 $sortInReverseOrder = true; 0045 0046 // END OF OPTIONS 0047 // ----------------------- 0048 0049 //print "Creating XML and thumbnails for SimpleViewer.<br>"; 0050 //print "-------------------------------------------------<br><br>"; 0051 //Get GD imaging library info 0052 $tgdInfo = getGDversion(); 0053 if ($tgdInfo == 0){ 0054 //print "Note: The GD imaging library was not found on this Server. Thumbnails will not be created. Please contact
your web server administrator."; 0055 } 0056 0057 if ($tgdInfo < 2){ 0058 //print "Note: The GD imaging library is version ".$tgdInfo." on this server. Thumbnails will be reduced quality. Please contact your web server administrator to upgrade GD version to 2.0.1 or later.<br><br>"; 0059 } 0060 0061 0062 if ($sortImagesByDate){ 0063 //print "Sorting images by date.<br>"; 0064 }else{ 0065 //print "Sorting images by filename.<br>"; 0066 } 0067 0068 if ($sortInReverseOrder){ 0069 //print "Sorting images in reverse order.<br><br>"; 0070 }else{ 0071 //print "Sorting images in forward order.<br><br>"; 0072 } 0073 0074 //loop thru images 0075 $xml = $options; 0076 $folder = opendir($imagePath); 0077 while($file = readdir($folder)) { 0078 if ($file[0] != "." "" $file[0] != ".." ) { 0079 if ($sortImagesByDate){ 0080 $files[$file] = filemtime($imagePath."/$file"); 0081 }else{ 0082 $files[$file] = $file; 0083 } 0084 } 0085 } 0086 0087 // now sort by date modified 0088 if ($sortInReverseOrder){ 0089 arsort($files); 0090 }else{ 0091 asort($files); 0092 } 0093 foreach($files as $key => $value) { 0094 $xml .= ' 0095 <IMAGE '; 0096 $xml .= 'nomImage="'.$key.'"'; 0097 //add auto captions: 'Image X' 0098 /*if ($showDownloadLinks){ 0099 $xml .= ' caption="<![CDATA[<a href="images/'.$key.'" target=" _blank"><U>Open image in new window</U></a>]]>"'; 0100 }else{ 0101 $xml .= ' caption=\'\''; 0102 } */ 0103 $xml .= ' />'; 0104 0105 /*print "- Created Image Entry for: $key<br>"; 0106 0107 if (!file_exists("./thumbs/".$key)){ 0108 if (createThumb($key)){ 0109 print "- Created Thumbnail for: $key<br>"; 0110 } 0111 } 0112 */ 0113 } 0114 0115 closedir($folder); 0116 0117 $xml .= ' 0118 </CHARLIESGALLERY>'; 0119 //next line can cause erroneous warnings 0120 //chmod( 'imageData.xml', 0777 ); 0121 $file = "gallery.xml"; 0122 if (!$file_handle = fopen($file,"w")) { 0123 //print "<br>Cannot open XML document: $file<br>"; 0124 } elseif (!fwrite($file_handle, $xml)) { 0125 //print "<br>Cannot write to XML document: $file<br>"; 0126 }else{ 0127 //print "<br>Successfully created XML document: $file<br>"; 0128 } 0129 fclose($file_handle); 0130 0131 0132 } 0133 0134 0135 // }}} 0136 // {{{ createThumb() 0137 0138 /** 0139 * Create a squared thumbnail from an existing image. 0140 * 0141 * @param string $file Location and name where the file is stored . 0142 * @return boolean 0143 * @access public 0144 * @author Christian Machmeier 0145 */ 0146 function createThumb($fileName) 0147 { 0148 0149 // Get information about the installed GD. 0150 $gdVersion = getGDversion(); 0151 0152 if ($gdVersion == false) { 0153 return false; 0154 } 0155 0156 $file = 'images/'.$fileName; 0157 $fileDest = 'thumbs/'.$fileName; 0158 0159 // Get the image dimensions. 0160 $dimensions = @getimagesize($file); 0161 $width = $dimensions[0]; 0162 $height = $dimensions[1]; 0163 0164 $outputX = 45; 0165 $outputY = 45; 0166 $quality = 85; 0167 0168 // The image is of vertical shape. 0169 if ($width < $height) { 0170 $deltaX = 0; 0171 $deltaY = ($height - $width) / 2; 0172 $portionX = $width; 0173 $portionY = $width; 0174 0175 // The image is of horizontal shape. 0176 } else if ($width > $height) { 0177 $deltaX = ($width - $height) / 2; 0178 $deltaY = 0; 0179 $portionX = $height; 0180 $portionY = $height; 0181 0182 // The image is of squared shape. 0183 } else { 0184 $deltaX = 0; 0185 $deltaY = 0; 0186 $portionX = $width; 0187 $portionY = $height; 0188 } 0189 0190 $imageSrc = @imagecreatefromjpeg($file); 0191 0192 // The thumbnail creation with GD1.x functions does the job. 0193 if ($gdVersion < 2 || $useCopyResized) { 0194 0195 // Create an empty thumbnail image. 0196 $imageDest = @imagecreate($outputX, $outputY); 0197 0198 // Try to create the thumbnail from the source image. 0199 if (@imagecopyresized($imageDest, $imageSrc, 0, 0, $deltaX, $deltaY, $outputX, $outputY, $portionX, $portionY)) { 0200 0201 // save the thumbnail image into a file. 0202 @imagejpeg($imageDest, $fileDest, $quality); 0203 0204 // Delete both image resources. 0205 @imagedestroy($imageSrc); 0206 @imagedestroy($imageDest); 0207 0208 return true; 0209 0210 } 0211 0212 } else { 0213 // The recommended approach is the usage of the GD2.x functions. 0214 0215 // Create an empty thumbnail image. 0216 $imageDest = @imagecreatetruecolor($outputX, $outputY); 0217 0218 // Try to create the thumbnail from the source image. 0219 if (@imagecopyresampled($imageDest, $imageSrc, 0, 0, $deltaX, $deltaY, $outputX, $outputY, $portionX, $portionY)) { 0220 0221 // save the thumbnail image into a file. 0222 @imagejpeg($imageDest, $fileDest, $quality); 0223 0224 // Delete both image resources. 0225 @imagedestroy($imageSrc); 0226 @imagedestroy($imageDest); 0227 0228 return true; 0229 } 0230 } 0231 0232 return false; 0233 } 0234 0235 function getGDversion() { 0236 static $gd_version_number = null; 0237 if ($gd_version_number === null) { 0238 // Use output buffering to get results from phpinfo() 0239 // without disturbing the page we're in. Output 0240 // buffering is "stackable" so we don't even have to 0241 // worry about previous or encompassing buffering. 0242 ob_start(); 0243 phpinfo(8); 0244 $module_info = ob_get_contents(); 0245 ob_end_clean(); 0246 if (preg_match("/\bgd\s+version\b[^\d ]+?([\d\.]+)/i", 0247 $module_info,$matches)) { 0248 $gd_version_number = $matches[1]; 0249 } else { 0250 $gd_version_number = 0; 0251 } 0252 } 0253 return $gd_version_number; 0254 } 0255 0256 ?>
Le fichier XML gènerè
<CHARLIESGALLERY> <IMAGE nomImage="IMG_0842.jpg" /> <IMAGE nomImage="IMG_0903.jpg" /> <IMAGE nomImage="IMG_1431.jpg" /> <IMAGE nomImage="IMG_1430.jpg" /> <IMAGE nomImage="IMG_1429.jpg" /> <IMAGE nomImage="IMG_1428.jpg" /> <IMAGE nomImage="IMG_1427.jpg" /> <IMAGE nomImage="IMG_0909.jpg" /> <IMAGE nomImage="IMG_0904.jpg" /> </CHARLIESGALLERY>