Mam takie kod(znaleziony w sieci):
<?php /*********************************************/ /* Fonction: ImageCreateFromBMP */ /* Author: DHKold */ /* Contact: admin@dhkold.com */ /* Date: The 15th of June 2005 */ /* Version: 2.0B */ /*********************************************/ function ImageCreateFromBMP($filename) { //Ouverture du fichier en mode binaire //1 : Chargement des ent?tes FICHIER if ($FILE['file_type'] != 19778) return FALSE; //2 : Chargement des ent?tes BMP '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. $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['decal'] = ($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 if ($BMP['colors'] < 16777216) { } //4 : Cr?ation de l'image $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'] == 24) elseif ($BMP['bits_per_pixel'] == 16) { $COLOR[1] = $PALETTE[$COLOR[1]+1]; } elseif ($BMP['bits_per_pixel'] == 8) { $COLOR[1] = $PALETTE[$COLOR[1]+1]; } elseif ($BMP['bits_per_pixel'] == 4) { 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) { 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 return FALSE; imagesetpixel($res,$X,$Y,$COLOR[1]); $X++; $P += $BMP['bytes_per_pixel']; } $Y--; $P+=$BMP['decal']; } //Fermeture du fichier return $res; } //********************************************************************************
******************** function create_thumbnail( $source_file, $destination_file, $max_dimension) { $aspect_ratio = $img_width / $img_height; if ( ($img_width > $max_dimension) || ($img_height > $max_dimension) ) // If either dimension is too big... { if ( $img_width > $img_height ) // For wide images... { $new_width = $max_dimension; $new_height = $new_width / $aspect_ratio; } elseif ( $img_width < $img_height ) // For tall images... { $new_height = $max_dimension; $new_width = $new_height * $aspect_ratio; } elseif ( $img_width == $img_height ) // For square images... { $new_width = $max_dimension; $new_height = $max_dimension; } } else { $new_width = $img_width; $new_height = $img_height; } // If it's already smaller, don't change the size. // Make sure these are integers. $thumbnail = imagecreatetruecolor($new_width,$new_height); // Creates a new image in memory. // The following block retrieves the source file. It assumes the filename extensions match the file's format. { $img_source = imagecreatefromjpeg($source_file); } // Here we resample and create the new jpeg. imagecopyresampled($thumbnail, $img_source, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height); imagejpeg( $thumbnail, $destination_file, 100 ); // Finally, we destroy the two images in memory. imagedestroy($img_source); imagedestroy($thumbnail); } ?>
Wszystko fajnie działa, gdy chcę utworzyć miniaturkę z normalnego zdjęcia jpg.
Problem występuje wtedy, gdy ma utworzyć miniaturkę z zdjęcia jpg z metadanymi (Exif).
Tworzy się wtedy czarna miniaturka.
Czy da się temu jakoś zaradzić?
Zdjęcie jpg z metadanymi (Exif): http://s.fothost.pl/upload/10/23/c15396e9.jpg