/** * Get the posted content for an image area * */ public static function SectionFromPost_Image(&$section, $dest_dir = '/data/_resized/img_type/') { global $page, $dataDir, $dirPrefix, $langmessage; $page->ajaxReplace = array(); //source file if (!empty($_REQUEST['file'])) { $source_file_rel = $_REQUEST['file']; } if (!empty($_REQUEST['src'])) { $source_file_rel = rawurldecode($_REQUEST['src']); if (!empty($dirPrefix)) { $len = strlen($dirPrefix); $source_file_rel = substr($source_file_rel, $len); } } $source_file_rel = '/' . ltrim($source_file_rel, '/'); $source_file_full = $dataDir . $source_file_rel; if (!file_exists($source_file_full)) { msg($langmessage['OOPS'] . ' (Source file not found)'); return false; } $src_img = \gp\tool\Image::getSrcImg($source_file_full); if (!$src_img) { msg($langmessage['OOPS'] . ' (Couldn\'t create image [1])'); return false; } //size and position variables $orig_w = imagesx($src_img); $orig_h = imagesy($src_img); $posx = self::ReqNumeric('posx', 0); $posy = self::ReqNumeric('posy', 0); $width = self::ReqNumeric('width', $orig_w); $height = self::ReqNumeric('height', $orig_h); //check to see if the image needs to be resized if ($posx == 0 && $posy == 0 && $width == $orig_w && $height == $orig_h) { $section['attributes']['src'] = $source_file_rel; $section['attributes']['height'] = $height; $section['attributes']['width'] = $width; $section['orig_src'] = $_REQUEST['src']; $section['posx'] = 0; $section['posy'] = 0; return true; } //destination file $name = basename($source_file_rel); $parts = explode('.', $name); //remove the time portion of the filename if (count($parts) > 1) { $time_part = array_pop($parts); if (!ctype_digit($time_part)) { $parts[] = $time_part; } } $name = implode('.', $parts); $time = self::ReqTime(); $dest_img_rel = $dest_dir . $name . '.' . $time . '.png'; $dest_img_full = $dataDir . $dest_img_rel; //make sure the folder exists if (!\gp\tool\Files::CheckDir(dirname($dest_img_full))) { msg($langmessage['OOPS'] . ' (Couldn\'t create directory)'); return false; } if (!\gp\tool\Image::createImg($src_img, $dest_img_full, $posx, $posy, 0, 0, $orig_w, $orig_h, $orig_w, $orig_h, $width, $height)) { msg($langmessage['OOPS'] . ' (Couldn\'t create image [2])'); return false; } $section['attributes']['src'] = $dest_img_rel; $section['attributes']['height'] = $height; $section['attributes']['width'] = $width; $section['orig_src'] = $_REQUEST['src']; $section['posx'] = $posx; $section['posy'] = $posy; \gp\admin\Content\Uploaded::CreateThumbnail($dest_img_full); return true; }
/** * Make sure newly uploaded images are within the site's max-size setting * */ public function MaxSize($added) { global $config; foreach ($added as $file) { \gp\tool\Image::CheckArea($file['realpath'], $config['maximgarea']); } }