diff --git a/e107_admin/image.php b/e107_admin/image.php index bcdacc50d..2db19a4d9 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -67,7 +67,7 @@ if($_GET['action'] == 'nav' && e_AJAX_REQUEST) //XXX Doesn't work correctly insi } - + require(e_HANDLER.'phpthumb/ThumbLib.inc.php'); // For resizing on import. $e_sub_cat = 'image'; @@ -277,6 +277,7 @@ class media_form_ui extends e_admin_form_ui $this->cats[$cat] = $row['media_cat_title']; } asort($this->cats);*/ + // require(e_HANDLER.'phpthumb/ThumbLib.inc.php'); // For resizing on import. if(varset($_POST['multiselect']) && varset($_POST['e__execute_batch']) && (varset($_POST['etrigger_batch']) == 'options__rotate_cw' || varset($_POST['etrigger_batch']) == 'options__rotate_ccw')) { @@ -285,6 +286,16 @@ class media_form_ui extends e_admin_form_ui $this->rotateImages($ids,$type); } + + if(varset($_POST['multiselect']) && varset($_POST['e__execute_batch']) && (varset($_POST['etrigger_batch']) == 'options__resize_2048' )) + { + $type = str_replace('options__','',$_POST['etrigger_batch']); + $ids = implode(",",$_POST['multiselect']); + $this->resizeImages($ids,$type); + } + + + } function resize_method($curval) @@ -305,6 +316,8 @@ class media_form_ui extends e_admin_form_ui $sql = e107::getDb(); $tp = e107::getParser(); $mes = e107::getMessage(); + ini_set('memory_limit', '150M'); + ini_set('gd.jpeg_ignore_warning', 1); $degrees = ($type == 'rotate_cw') ? 270 : 90; @@ -321,23 +334,115 @@ class media_form_ui extends e_admin_form_ui $mes->addDebug("Attempting to rotate by {$degrees} degrees: ".basename($original)); $source = imagecreatefromjpeg($original); - - $rotate = imagerotate($source, $degrees, 0); + + try + { + $rotate = imagerotate($source, $degrees, 0); + } + catch (Exception $e) + { + $mes->addError("Not enough memory available to rotate: ".basename($original)); + } + $srch = array(".jpg",".jpeg"); $cacheFile = str_replace($srch,"",strtolower(basename($original)))."_(.*)\.cache\.bin"; - if(imagejpeg($rotate,$original,100)) + try { + imagejpeg($rotate,$original,80); $mes->addSuccess("Rotated: ".basename($original)); e107::getCache()->clearAll('image',$cacheFile); $mes->addDebug("Clearing Image cache with mask: ".$cacheFile); - } + } + catch (Exception $e) + { + $mes->addError("Not enough memory available to rotate: ".basename($original)); + } } } } + + + /** + * Resize a single image. + * @param string + * @param int + * @param int + */ + private function resizeImage($oldpath,$img_import_w,$img_import_h) + { + + try + { + $thumb = PhpThumbFactory::create($oldpath); + $thumb->setOptions(array('correctPermissions' => true)); + } + catch (Exception $e) + { + $mes->addError($e->getMessage()); + return FALSE; + // return $this; + } + if($WM) // TODO Add watermark prefs for alpha and position. + { + $thumb->resize($img_import_w,$img_import_h)->addWatermark($watermark, 'rightBottom', 30, 0, 0)->save($oldpath); + } + else + { + if($thumb->resize($img_import_w,$img_import_h)->save($oldpath)) + { + return TRUE; + } + } + + } + + + + + private function resizeImages($ids,$type) + { + + $sql = e107::getDb(); + $sql2 = e107::getDb('sql2'); + $mes = e107::getMessage(); + $tp = e107::getParser(); + $fl = e107::getFile(); + + // Max size is 6 megapixel. + $img_import_w = 2816; + $img_import_h = 2112; + + if($sql->db_Select("core_media","media_id,media_url","media_id IN (".$ids.") AND media_type = 'image/jpeg' ")) + { + while($row = $sql->db_Fetch()) + { + $path = $tp->replaceConstants($row['media_url']); + + $mes->addDebug("Attempting to resize: ".basename($path)); + + if($this->resizeImage($path,$img_import_w,$img_import_h)) + { + + $info = $fl->get_file_info($path); + $mes->addSuccess("Resizing: ".basename($path)); + $mes->addSuccess(print_a($info,true)); + $dim = intval($info['img-width'])." x ".intval($info['img-height']); + $sql2->db_Update("core_media","media_dimensions = '".$dim."', media_size = '".intval($info['fsize'])."' WHERE media_id = ".intval($row['media_id'])." LIMIT 1"); + } + else + { + $mes->addError("Resizing: ".basename($path)); + } + } + } + + + + } - function resize_dimensions($curval) // ie. never manually resize another image again! + private function resize_dimensions($curval) // ie. never manually resize another image again! { $text = ""; $frm = e107::getForm(); @@ -388,8 +493,9 @@ class media_form_ui extends e_admin_form_ui if($value == 'batch') { return array( + "resize_2048" => "Reduce Oversized Images", "rotate_cw" => "Rotate 90° cw", - "rotate_ccw" => "Rotate 90° ccw" + "rotate_ccw" => "Rotate 90° ccw" ); } @@ -1413,11 +1519,12 @@ class media_admin_ui extends e_admin_ui
"; - $c = 0; + // $c = 0; foreach($files as $f) { $default = $this->getFileXml($f['fname']); $f = $fl->cleanFileName($f,true); + $c = md5($f['path'].$f['fname']); if($f['error']) { @@ -1434,16 +1541,15 @@ class media_admin_ui extends e_admin_ui