this should be here to stop it using any ext >_<

This commit is contained in:
Daku 2012-02-16 03:03:36 +00:00
parent d33853cee0
commit 78a16885e5

View File

@ -62,19 +62,7 @@ class ResizeImage extends Extension {
global $config; global $config;
$image_obj = Image::by_id($event->image_id); $image_obj = Image::by_id($event->image_id);
$isanigif = 0; if($config->get_bool("resize_upload") == true && ($image_obj->ext == "jpg" || $image_obj->ext == "png" || $image_obj->ext == "gif")){
if($image_obj->ext == "gif"){
$image_filename = warehouse_path("images", $image_obj->hash);
if(!($fh = @fopen($image_filename, 'rb'))){ //check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
return false;
}
while(!feof($fh) && $isanigif < 2) {
$chunk = fread($fh, 1024 * 100);
$isanigif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
}
}
if($config->get_bool("resize_upload") == true && ($image_obj->ext == "jpg" || $image_obj->ext == "png" || $isanigif === 0)){
$width = $height = 0; $width = $height = 0;
if ($config->get_int("resize_default_width") !== 0) { if ($config->get_int("resize_default_width") !== 0) {
@ -83,20 +71,32 @@ class ResizeImage extends Extension {
if ($config->get_int("resize_default_height") !== 0) { if ($config->get_int("resize_default_height") !== 0) {
$height = $config->get_int("resize_default_height"); $height = $config->get_int("resize_default_height");
} }
$isanigif = 0;
try { if($image_obj->ext == "gif"){
$this->resize_image($event->image_id, $width, $height); $image_filename = warehouse_path("images", $image_obj->hash);
} catch (ImageResizeException $e) { if(!($fh = @fopen($image_filename, 'rb'))){ //check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
$this->theme->display_resize_error($page, "Error Resizing", $e->error); return false;
}
while(!feof($fh) && $isanigif < 2) {
$chunk = fread($fh, 1024 * 100);
$isanigif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
}
} }
if($isanigif == 0){
try {
$this->resize_image($event->image_id, $width, $height);
} catch (ImageResizeException $e) {
$this->theme->display_resize_error($page, "Error Resizing", $e->error);
}
//Need to generate thumbnail again... //Need to generate thumbnail again...
//This only seems to be an issue if one of the sizes was set to 0. //This only seems to be an issue if one of the sizes was set to 0.
$image_obj = Image::by_id($event->image_id); //Must be a better way to grab the new hash than setting this again.. $image_obj = Image::by_id($event->image_id); //Must be a better way to grab the new hash than setting this again..
send_event(new ThumbnailGenerationEvent($image_obj->hash, $image_obj->ext, true)); send_event(new ThumbnailGenerationEvent($image_obj->hash, $image_obj->ext, true));
log_info("resize", "Image #{$event->image_id} has been resized to: ".$width."x".$height); log_info("resize", "Image #{$event->image_id} has been resized to: ".$width."x".$height);
//TODO: Notify user that image has been resized. //TODO: Notify user that image has been resized.
}
} }
} }