$memoryLimit) { error_log('IMAGE_MEMORY usage: '.memory_get_usage().", needed: $memoryNeeded, limit: $memoryLimit\n", 3, '/var/log/web04/php_error_log'); return false; } return true; } #------------------------------------------------------------------------------ function get_graphic_type($nr) { $_type = array(0 => 'unknown', 1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF(intel byte order)', 8 => 'TIFF(motorola byte order)', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF', 15 => 'WBMP', 16 => 'XBM'); if (isset($_type[$nr])) return $_type[$nr]; return $_type[0]; } #------------------------------------------------------------------------------ # ToDo : Free memory testen, komprimierte Bilder verarbeiten if (!function_exists('ImageCreateFromBMP')) { function ImageCreateFromBMP($filename) { //Ouverture du fichier en mode binaire if (! $f1 = fopen($filename,"rb")) return FALSE; if (! flock($f1, LOCK_SH)) { fclose($f1); return FALSE; } //1 : Chargement des ent?tes FICHIER $buffer = fread($f1,14); if (strlen($buffer) != 14) { fclose($f1); return false; } $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", $buffer); if ($FILE['file_type'] != 19778) { fclose($f1); return FALSE; } //2 : Chargement des ent?tes BMP $buffer = fread($f1,40); if (strlen($buffer) != 40) { fclose($f1); return false; } $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'. '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. '/Vvert_resolution/Vcolors_used/Vcolors_important', $buffer); $BMP['colors'] = pow(2,$BMP['bits_per_pixel']); if ($BMP['size_bitmap'] == 0) $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset']; $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8; $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']); $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4); $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4); $BMP['decal'] = 4-(4*$BMP['decal']); if ($BMP['decal'] == 4) $BMP['decal'] = 0; //3 : Chargement des couleurs de la palette $PALETTE = array(); if ($BMP['colors'] < 16777216) { $PALETTE = unpack('V'.$BMP['colors'], fread($f1,$BMP['colors']*4)); } //4 : Creation de l'image $IMG = fread($f1,$BMP['size_bitmap']); fclose($f1); if (strlen($IMG) != $BMP['size_bitmap']) { return false; } $VIDE = chr(0); $res = imagecreatetruecolor($BMP['width'],$BMP['height']); $P = 0; $Y = $BMP['height']-1; while ($Y >= 0) { $X=0; while ($X < $BMP['width']) { if ($BMP['bits_per_pixel'] == 32) { $COLOR = unpack("V",substr($IMG,$P,4)); ## Transparenz nachbessern } elseif ($BMP['bits_per_pixel'] == 24) { $COLOR = unpack("V",substr($IMG,$P,3).$VIDE); ## Transparenz nachbessern } elseif ($BMP['bits_per_pixel'] == 16) { $COLOR = unpack("n",substr($IMG,$P,2)); $COLOR[1] = $PALETTE[$COLOR[1]+1]; } elseif ($BMP['bits_per_pixel'] == 8) { $COLOR = unpack("n",$VIDE.substr($IMG,$P,1)); $COLOR[1] = $PALETTE[$COLOR[1]+1]; } elseif ($BMP['bits_per_pixel'] == 4) { $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1)); if (($P*2)%2 == 0) $COLOR[1] = ($COLOR[1] >> 4) ; else $COLOR[1] = ($COLOR[1] & 0x0F); $COLOR[1] = $PALETTE[$COLOR[1]+1]; } elseif ($BMP['bits_per_pixel'] == 1) { $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1)); if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7; elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6; elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5; elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4; elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3; elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2; elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1; elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1); $COLOR[1] = $PALETTE[$COLOR[1]+1]; } else { imagedestroy($res); return FALSE; } imagesetpixel($res,$X,$Y,$COLOR[1]); $X++; $P += $BMP['bytes_per_pixel']; } $Y--; $P+=$BMP['decal']; } return $res; } } #------------------------------------------------------------------------------ # Pixelbild im Speicher aufbauen. if (!function_exists('image_expand')) { function image_expand($source) { if (!is_readable($source)) return false; $_img_meta = getimagesize($source); if ($_img_meta === false) return false; if (!image_check_memory($_img_meta)) return false; switch ($_img_meta[2]) { case 1: ## GIF-Bild if (!function_exists("ImageCreatefromgif")) return false; $src_img = ImageCreatefromgif($source); break; case 2: ## JPG-Bild if (!function_exists("ImageCreatefromjpeg")) return false; $src_img = ImageCreatefromjpeg($source); break; case 3: ## PNG-Bild if (!function_exists("ImageCreatefromPNG")) return false; $src_img = ImageCreatefrompng($source); break; case 6: ## BMP-Bild (Windows) if (!function_exists("ImageCreateFromBMP")) return false; $src_img = ImageCreateFromBMP($source); break; case 15: ## WBMP-Bild (IBM) if (!function_exists("ImageCreatefromWBMP")) return false; $src_img = ImageCreatefromwbmp($source); break; default: $src_img = false; } return $src_img; } } #------------------------------------------------------------------------------ # ToDo: Die anderen möglichen Ausgabeformate einbauen # Prüfen, ob das target erstellt werden darf (Schreibreichte) # # function image_scale($source, $target, $maxwidth, $maxheight) { if (!$img_src = image_expand($source)) return false; if (imagesx($img_src) > imagesy($img_src)) ## landscape { $newwidth = $maxwidth; $newheight = intval($newwidth * imagesy($img_src) / imagesx($img_src)); } else ## portrait { $newheight = $maxheight; $newwidth = intval($newheight * imagesx($img_src) / imagesy($img_src)); } ## Speicherbedarf für neues Bild bestimmen if (!image_check_memory(array('0'=>$newwidth, '1'=>$newheight, 'bits'=>8, 'channels'=>3)) ## for TrueColor # or !is_writable($target) ) { imagedestroy($img_src); return false; } $new_image = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($new_image, $img_src, 0,0,0,0, $newwidth, $newheight, imagesx($img_src),imagesy($img_src)); #imagecopyresized ( $new_image, $src_img, 0,0,0,0, $newwidth, $newheight, imagesx($img_src),imagesy($img_src)); return imagejpeg($new_image, $target); imagedestroy($img_src); imagedestroy($new_image); } #------------------------------------------------------------------------------ # nutzlos # function get_imagetype($filename) { $_meta = getimagesize($filename); if ($_meta === false) return false; if (!isset($_meta[2])) return 'unknown'; return $_meta[2]; } #============================================================================== # php main "Test-Sektion" #============================================================================== # allgemein ToDo: Fehlerbehandlung, Fehlernummern bereitstellen, Logging # # # # $_files = glob('musterbilder1/*.*'); echo "
\n";

echo htmlspecialchars(print_r($_files,1));


foreach ($_files as $key => $filename)
{
  #$target = "thumbs1/".substr('00000'.$key,-5)."-".basename($filename).".jpg";
  $target = "thumbs1/".basename($filename).".jpg";

  if (!file_exists($target) or (filemtime($target) < filemtime($filename)))
  {
    image_scale($filename, $target, 200,200); 
  }  
}


foreach ($_files as $key => $filename)
{

  echo $filename, "\t", image_type_to_extension(get_imagetype($filename)), "
\n"; $_imginfo = getimagesize($filename); echo htmlspecialchars(print_r($_imginfo,1)); } foreach ($_files as $key => $filename) { echo $filename, "\t", get_graphic_type(get_imagetype($filename)), "
\n"; } echo "
\n"; ?>