function resize_images() { global $xoopsUser, $xoopsLogger, $xoopsSecurity; set_time_limit(0); error_reporting(0); $xoopsLogger->activated = false; $params = rmc_server_var($_GET, 'data', ''); $id = rmc_server_var($_GET, 'img', 0); if ($params == '') { send_error(__('Unauthorized!', 'rmcommon')); } if ($id <= 0) { send_error(__('Invalid image!', 'rmcommon')); } $params = TextCleaner::decrypt($params); $data = explode('|', $params); if ($data[0] != $xoopsUser->uid()) { send_error(__('Unauthorized!', 'rmcommon')); } if ($data[1] != RMCURL . '/images.php') { send_error(__('Unauthorized!', 'rmcommon')); } if (!$xoopsSecurity->check(false, $data[2])) { send_error(__('Unauthorized!', 'rmcommon')); } $image = new RMImage($id); if ($image->isNew()) { send_error(__('Image not found!', 'rmcommon')); } // Resize image $cat = new RMImageCategory($image->getVar('cat')); if (!$cat->user_allowed_toupload($xoopsUser)) { send_error(__('Unauthorized', 'rmcommon')); } $sizes = $cat->getVar('sizes'); $updir = XOOPS_UPLOAD_PATH . '/' . date('Y', $image->getVar('date')) . '/' . date('m', time()); $upurl = XOOPS_UPLOAD_URL . '/' . date('Y', $image->getVar('date')) . '/' . date('m', time()); $width = 0; $tfile = ''; foreach ($sizes as $size) { if ($size['width'] <= 0 && $size['height'] <= 0) { continue; } $fd = pathinfo($updir . '/' . $image->getVar('file')); $name = $updir . '/sizes/' . $fd['filename'] . '_' . $size['width'] . 'x' . $size['height'] . '.' . $fd['extension']; $sizer = new RMImageResizer($updir . '/' . $image->getVar('file'), $name); switch ($size['type']) { case 'crop': $sizer->resizeAndCrop($size['width'], $size['height']); break; default: if ($size['width'] <= 0 || $size['height'] <= 0) { $sizer->resizeWidth($size['width']); } else { $sizer->resizeWidthOrHeight($size['width'], $size['height']); } break; } if ($size['width'] <= $width || $width == 0) { $width = $size['width']; $tfile = str_replace(XOOPS_UPLOAD_PATH, XOOPS_UPLOAD_URL, $name); } } $ret['message'] = sprintf(__('%s done!', 'rmcommon'), $image->getVar('file')); $ret['done'] = 1; $ret['file'] = $tfile; $ret['title'] = $image->getVar('title'); echo json_encode($ret); die; }
/** * Resize images */ function gs_resize_images() { global $xoopsUser, $xoopsLogger, $xoopsSecurity; set_time_limit(0); $mc = RMUtilities::module_config('galleries'); $params = rmc_server_var($_GET, 'data', ''); $id = rmc_server_var($_GET, 'img', 0); if ($params == '') { send_error(__('Unauthorized!', 'galleries')); } if ($id <= 0) { send_error(__('Invalid image!', 'galleries')); } $params = TextCleaner::decrypt($params); $data = explode('|', $params); if ($data[0] != $xoopsUser->uid()) { send_error(__('Unauthorized!', 'galleries')); } if ($data[1] != GS_URL . '/admin/images.php') { send_error(__('Unauthorized!', 'galleries')); } if (!$xoopsSecurity->check(false, $data[2])) { send_error(__('Unauthorized!', 'galleries')); } $image = new GSImage($id); if ($image->isNew()) { send_error(__('Image not found!', 'galleries')); } $thSize = $mc['image_ths']; $imgSize = $mc['image']; if ($thSize[0] <= 0) { $thSize[0] = 100; } if (!isset($thSize[1]) || $thSize[1] <= 0) { $thSize[1] = $thSize[0]; } if ($imgSize[0] <= 0) { $imgSize[0] = 500; } if (!isset($imgSize[1]) || $imgSize[1] <= 0) { $imgSize[1] = $imgSize[0]; } $xu = new GSUser($image->owner(), 1); $updir = rtrim($mc['storedir'], '/') . "/" . $xu->uname(); $upurl = str_replace(XOOPS_ROOT_PATH, XOOPS_URL, $updir); $upths = rtrim($mc['storedir'], '/') . "/" . $xu->uname() . "/ths"; $width = 0; $tfile = ''; // Almacenamos la imágen original if ($mc['saveoriginal']) { copy($updir . '/' . $image->image(), $mc['storedir'] . '/originals/' . $image->image()); } $fd = pathinfo($updir . '/' . $image->image()); $filename = $image->image(); $redim = new RMImageResizer($updir . '/' . $image->image(), $updir . '/' . $image->image()); switch ($mc['redim_image']) { case 0: //Recortar miniatura $redim->resizeWidth($imgSize[0]); $redim->setTargetFile($upths . "/{$filename}"); $redim->resizeAndCrop($thSize[0], $thSize[1]); break; case 1: //Recortar imagen grande $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]); $redim->setTargetFile($upths . "/" . $image->image()); $redim->resizeWidth($thSize[0]); break; case 2: //Recortar ambas $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]); $redim->setTargetFile($upths . "/{$filename}"); $redim->resizeAndCrop($thSize[0], $thSize[1]); break; case 3: //Redimensionar $redim->resizeWidth($imgSize[0]); $redim->setTargetFile($upths . "/{$filename}"); $redim->resizeWidth($thSize[0]); break; } $tfile = $upurl . '/ths/' . $image->image(); $ret['message'] = sprintf(__('%s done!', 'galleries'), $image->image()); $ret['done'] = 1; $ret['file'] = $tfile; $ret['title'] = $image->image(); echo json_encode($ret); die; }