$ref, "search" => $search, "offset" => $offset, "order_by" => $order_by, "sort" => $sort, "k" => $k ); $view_url = generateURL($baseurl_short . 'pages/view.php',$urlparams); $resource=get_resource_data($ref); if ($resource===false || $ref <= 0) { error_alert($lang['resourcenotfound']); exit(); } if (!in_array(strtoupper($resource['file_extension']), $cropper_allowed_extensions)) { error_alert($lang['error_resource_not_image_extension'] . ' (' . implode(', ', $cropper_allowed_extensions) . ')'); exit(); } # Load edit access level $edit_access=get_edit_access($ref); $access =get_resource_access($ref); $cropperestricted = in_array($usergroup,$cropper_restricteduse_groups); $sswidth = 1920; $ssheight = 1080; // Create array to hold errors $errors = array(); $blockcrop = false; // Check sufficient access if ($access!=0 || ($saveaction =="original" && !$edit_access)) { $blockcrop= true; $error = $lang['error-permissiondenied']; } elseif(intval($user_dl_limit) > 0) { $download_limit_check = get_user_downloads($userref,$user_dl_days); if($download_limit_check >= $user_dl_limit) { $blockcrop= true; $error = $lang['download_limit_error']; } } if($blockcrop) { if(getval("ajax","") != "") { error_alert($error, true,200); // 200 so that history works } else { include "../../../include/header.php"; $onload_message = array("title" => $lang["error"],"text" => $error); include "../../../include/footer.php"; } exit(); } $imversion = get_imagemagick_version(); // retrieve image paths for preview image and original file $orig_ext = $resource["file_extension"]; hook('transformcropbeforegetsize'); $originalpath = get_resource_path($ref,true,'',false,$orig_ext); debug(sprintf('[transform][pages/crop][line@%d] $originalpath = %s ', __LINE__, $originalpath)); $usesize = "scr"; $useext = "jpg"; if(file_exists($originalpath)) { // For SVGs it is hard to determine the size (at the moment (PHP7 - 29/12/2017) getimagesize does not support it) // Note: if getSvgSize() can extract the width and height then the crop will work as expected, otherwise the output will // be the full size (ie. not cropped) if(strtoupper($orig_ext) == 'SVG') { list($origwidth, $origheight) = getSvgSize($originalpath); $usesize = ""; $useext = $orig_ext; } else { $origsizes = try_getimagesize($originalpath); if ($origsizes === false) { $identify_path = get_utility_path('im-identify'); $identify_results = run_command( "{$identify_path} -format '%w,%h' originalpath", false, [ 'originalpath' => new CommandPlaceholderArg($originalpath, 'is_valid_rs_path'), ] ); if(preg_match("~\d+,\d+~",$identify_results)) { $origsizes = explode(',',$identify_results); } else { $errors[] = "Unable to get image resolution"; $origsizes = [0,0]; } } $origwidth = $origsizes[0]; $origheight = $origsizes[1]; } } else { $errors[] = "Unable to find original file"; } // Check if an uncropped preview exists $previewsourcepath = $org = get_resource_path($ref,true,"original_copy",false,$useext); debug(sprintf('[transform][pages/crop][line@%d] $org = %s ', __LINE__, $org)); if(!file_exists($org)) { $previewsourcepath = get_resource_path($ref,true,$usesize,false,$useext); debug(sprintf('[transform][pages/crop][line@%d] $previewsourcepath = %s ', __LINE__, $previewsourcepath)); if(!file_exists($previewsourcepath)) { $previewsourcepath=get_preview_source_file($ref, $orig_ext, false, true,-1,!is_null($resource["file_path"])); debug(sprintf('[transform][pages/crop][line@%d] $previewsourcepath = %s ', __LINE__, $previewsourcepath)); } } // Check if preview is same aspect ratio as original $predims = try_getimagesize($previewsourcepath); $preratio = round($predims[0]/$predims[1],1); $origratio = round($origwidth/$origheight,1); if($preratio !== $origratio) { // The preview source file has been altered relative to the original. Use the original // instead because the final transform will use the original and any transformations will otherwise be incorrect $org = $previewsourcepath = $originalpath; } // Get the actions that have been requested $imgactions = array(); // Transformations must be carried out in the order the user performed them $tfactions = getval("tfactions",""); debug(sprintf('[transform][pages/crop] $tfactions = %s ', $tfactions)); $imgactions["tfactions"] = explode(",",$tfactions); $imgactions["quality"] = getval("quality",100,true); $imgactions["resolution"] = getval("resolution",0,true); $imgactions["gamma"] = getval("gamma",50,true); $imgactions["srgb"] = ($cropper_jpeg_rgb || ($cropper_srgb_option && getval("use_srgb","") != "")) && $saveaction != "original"; // Generate a preview image for the operation if it doesn't already exist $crop_pre_file = get_temp_dir(false,'') . "/transform_" . $ref . "_" . md5($username . date("Ymd",time()) . $scramble_key) . ".jpg"; $crop_pre_url = $baseurl . "/pages/download.php?tempfile=transform_" . $ref . "_" . date("Ymd",time()) . ".jpg"; $preview_actions = $imgactions; $preview_actions["new_width"] = 600; $preview_actions["new_height"] = 600; $preview_actions["preview"] = true; debug(sprintf('[transform][pages/crop][line@%d] $previewsourcepath = %s ', __LINE__, $previewsourcepath)); debug(sprintf('[transform][pages/crop][line@%d] $crop_pre_file = %s ', __LINE__, $crop_pre_file)); $generated = transform_file($previewsourcepath,$crop_pre_file, $preview_actions); if($reload_image) { if($generated) { $response['message'] = "SUCCESS"; } else { $response['message'] = $lang["transform_preview_gen_error"]; } exit(json_encode($response)); } elseif(!$generated) { error_alert($lang["transform_preview_gen_error"]); exit(); } $cropsizes = false; if(file_exists($crop_pre_file)) { $cropsizes = try_getimagesize($crop_pre_file); } else { $errors[] = "Unable to find preview image"; } if($cropsizes) { $cropwidth = $cropsizes[0]; $cropheight = $cropsizes[1]; } else { $errors[] = "Unable to determine preview image dimensions"; } # check that crop width and crop height are > 0 if ($cropwidth == 0 || $cropheight == 0) { error_alert($lang['error-dimension-zero'], false); exit(); } // Get parameters from Manage slideshow page $manage_slideshow_action = getval('manage_slideshow_action', ''); $manage_slideshow_id = getval('manage_slideshow_id', ''); $return_to_url = getval('return_to_url', ''); $terms_url = $baseurl_short."pages/terms.php?ref=".$ref; if ($saveaction != '' && enforcePostRequest(false)) { debug("[transform][pages/crop] save action triggered - $saveaction"); $imgactions["repage"] = $cropper_use_repage; // Get values from jcrop selection $width = getval('width',0,true); $height = getval('height',0,true); $xcoord = getval('xcoord',0,true); $ycoord = getval('ycoord',0,true); // Get required size $new_width = getval('new_width',0,true); $new_height = getval('new_height',0,true); if ($width == 0 && $height == 0) { if (($new_width > 0 || $new_height > 0) || $cropperestricted) { // the user did not indicate a crop. presumably they are scaling $verb = $lang['scaled']; } elseif($new_width == 0 && $new_height == 0) { // No scaling - maybe just rotation/image tweaks $verb = $lang['tweaked']; } } elseif (!$cropperestricted) { $verb = $lang['cropped']; $imgactions["crop"] = true; // Get jCrop selection info $imgactions["xcoord"] = $xcoord; $imgactions["ycoord"] = $ycoord; $imgactions["height"] = $height; $imgactions["width"] = $width; // Required dimensions for new image $imgactions["new_height"] = $new_height; $imgactions["new_width"] = $new_width; // Pass dimensions of crop preview to allow calculations $imgactions["cropheight"] = $cropheight; $imgactions["cropwidth"] = $cropwidth; } // Determine output format // prefer what the user requested. If nothing, look for configured default. If nothing, use same as original $new_ext = strtolower(getval("new_ext","")); if ($saveaction == "slideshow" || $saveaction == "preview") { $new_ext = "jpg"; } elseif ($new_ext != "") { // is this an allowed extension? if (!in_array(strtoupper($new_ext),$cropper_formatarray)) { $new_ext = strtolower($orig_ext); } } elseif (isset($cropper_default_target_format)) { $new_ext = strtolower($cropper_default_target_format); } else { $new_ext = strtolower($orig_ext); } if (($saveaction == "original" && !$edit_access) || ($saveaction == "slideshow" && !checkperm('a'))) { error_alert($lang['error-permissiondenied'], true,200); exit(); } // Set path to output file $tmpdir = get_temp_dir(); if(!is_dir("$tmpdir/transform_plugin")) { // If it does not exist, create it. mkdir("$tmpdir/transform_plugin", 0777); } $newpath = "$tmpdir/transform_plugin/download_" . $ref . uniqid() . "." . $new_ext; // Preserve original file preview (source) in case transforms are used for previews if(!file_exists($org) && $saveaction != "original") { debug("[transform][pages/crop] copy($previewsourcepath, $org)"); copy($previewsourcepath, $org); } if ($use_system_icc_profile_config && $saveaction != "original") { $imgactions = array_merge($imgactions, transform_apply_icc_profile($ref, $originalpath)); } // Perform the actual transformation $transformed = transform_file($originalpath, $newpath, $imgactions); if($transformed) { // get final pixel dimensions of resulting file $newfilesize = filesize_unlimited($newpath); $newfiledimensions = try_getimagesize($newpath); $newfilewidth = $newfiledimensions[0]; $newfileheight = $newfiledimensions[1]; $name = getval("filename",""); $filename = safe_file_name($name); if ($cropper_use_filename_as_title) { if(trim((string)$filename) == "") { // Compute a file name using file naming configuration $filename = get_download_filename($ref, "", "", $new_ext); } else { $filename .= "." . $new_ext; } } else { if (trim((string)$filename) == "") { $filename = $ref . "_" . strtolower($lang['transformed']); } $filename .= "." . $new_ext; } // Use the resultant file as requested if ($saveaction == "alternative" && $cropper_enable_alternative_files) { $description = getval("description",""); $alt_type = getval('alt_type',''); $mpcalc = round(($newfilewidth*$newfileheight)/1000000,1); $mptext = $mpcalc == 0 ? "" : " ($mpcalc " . $lang["megapixel-short"] . ")"; $description .= (trim($description) == "" ? "": " - " ) . $newfilewidth . " x " . $newfileheight . " " . $lang['pixels'] . " " . $mptext; $newfile = add_alternative_file($ref,$name,$description,$filename,$new_ext,$newfilesize,$alt_type); $altpath = get_resource_path($ref, true, "", true, $new_ext, -1, 1, false, "", $newfile); rename($newpath,$altpath); resource_log($ref,'b','',"$new_ext " . strtolower($verb) . " to $newfilewidth x $newfileheight"); create_previews($ref,false,$new_ext,false,false,$newfile); redirect($view_url); exit(); } elseif ($saveaction == "original" && $cropper_transform_original && $edit_access && !$cropperestricted) { // Replace the original file with the cropped file in newpath // By default keep original as alternative file. To prevent this $replace_resource_preserve_option must be enabled and the user select not to. $keep_original = true; if ($replace_resource_preserve_option && getval("keep_original", "") == "") { $keep_original = false; } $success = replace_resource_file($ref,$newpath,true,false,$keep_original); if (!$success) { $onload_message = array("title" => $lang["error"],"text" =>str_replace("%res",$ref,$lang['error-transform-failed'])); } else { // Original file has been updated so remove original_copy as invalid now if (file_exists($org)) { unlink($org); } } hook("transformcropafterreplaceoriginal"); if('' !== $return_to_url) { redirect($return_to_url); } redirect($view_url); exit(); } elseif ($saveaction == "slideshow" && !$cropperestricted && checkperm('a')) { # Produce slideshow. $sequence = getval("sequence", 0, true); if ($sequence == 0) { error_alert($lang['error_slideshow_invalid'], false); exit(); } if(!checkperm('a')) { $onload_message = array("title" => $lang["error"],"text" =>$lang['error-permissiondenied']); } if(file_exists(__DIR__ . '/../../../' . $homeanim_folder . '/' . $sequence . '.jpg') && !is_writable(__DIR__ . '/../../../' . $homeanim_folder . '/' . $sequence . '.jpg')) { error_alert(str_replace("[path]",realpath(__DIR__ . '/../../../' . $homeanim_folder), $lang['error-file-permissions'])); exit(); } rename($newpath,__DIR__ . "/../../../".$homeanim_folder."/" . $sequence . ".jpg"); set_slideshow($sequence, $ref); unlink($crop_pre_file); redirect($baseurl_short . "pages/home.php"); exit(); } elseif ($saveaction == "download") { // Move file to user's temp location and then redirect to download via terms/usage $randstring=md5(rand() . microtime()); $dlfile = get_temp_dir(false,'user_downloads') . "/" . $ref . "_" . md5($username . $randstring . $scramble_key) . "." . $new_ext; rename($newpath,$dlfile); $download_url = generateURL($baseurl_short . "pages/download.php", [ "userfile" => $ref . "_" . $randstring . "." . $new_ext, "filename" => strip_extension($filename) ]); $dlurl = generateURL($baseurl_short . "pages/download_progress.php", ['url' => $download_url, 'ref' => $ref]); if ($download_usage) { $dlurl = generateURL("pages/download_usage.php",["url" => $dlurl]); } $url_params["url"]=$dlurl; $redirect_to_terms_url=generateURL("pages/terms.php",$url_params); redirect($redirect_to_terms_url); exit(); } elseif ($saveaction == "preview") { $pretmp = get_resource_path($ref,true,"tmp",true,"jpg"); $result = rename($newpath, $pretmp); # Create previews create_previews($ref,false,"jpg",true); redirect($view_url); exit(); } hook("aftercropfinish"); // If other pages request us to go back to them rather then on the view page, do so if('' !== $return_to_url) { redirect($return_to_url); } // send user back to view page redirect($view_url); exit(); } else { $onload_message = array("title" => $lang["error"],"text" =>str_replace("%res",$ref,$lang['error-transform-failed'])); } } // get resource info $resource = get_resource_data($ref); // retrieve path to image and figure out size we're using if ((int) $resource["has_image"] !== RESOURCE_PREVIEWS_NONE) { if (!file_exists($crop_pre_file)) { error_alert($lang['noimagefound']); exit(); } $origpresizes = try_getimagesize($crop_pre_file); $origprewidth = $origpresizes[0]; $origpreheight = $origpresizes[1]; } else { echo escape($lang['noimagefound']); exit; } include "../../../include/header.php"; ?>

$lang["systemsetup"], 'href' => $baseurl_short . "pages/admin/admin_home.php", 'menu' => true ), array( 'title' => $lang["manage_slideshow"], 'href' => $baseurl_short . "pages/admin/admin_manage_slideshow.php", ) ); } else { $links_trail = array( array( 'title' => $lang["backtoview"] . " #" . $ref, 'href' => $view_url, ) ); } $links_trail[] = array('title' => $saveaction == "original" ? $lang['imagetoolstransformoriginal'] : $lang['imagetoolstransform'], 'help' => "plugins/transform", ); renderBreadcrumbs($links_trail); ?>

$lang["download"]); if ($cropper_enable_replace_slideshow && !$cropperestricted && checkperm('t') && is_writable(__DIR__."/../../../" . $homeanim_folder)) { $saveactions["slideshow"] = $lang['replaceslideshowimage']; } if ($cropper_enable_alternative_files && $edit_access && !$cropperestricted) { $saveactions["alternative"] = $lang['savealternative']; } if($cropper_transform_original && !$cropperestricted) { $saveactions["original"] = $lang['transform_original']; } if($edit_access) { $saveactions["preview"] = $lang['useaspreviewimage']; } $imagetools = array(); if('' === trim($manage_slideshow_action)) { $imagetools[] = array( "name" => "Crop", "action" => "toggleCropper();jQuery('.imagetools_actions').hide();jQuery('#croptools').show();jQuery('#imagetools_crop_actions').show();return false;", "icon" => "fa fa-fw fa-crop", ); } $imagetools[] = array( "name" => "Reset", "action" => "cropReload('reset');return false;", "icon" => "fa fa-fw fa-history", ); if($cropper_rotation) { $imagetools[] = array( "name" => "Rotate", "action" => "cropReload('rotate');return false;", "icon" => "fa fa-fw fa-rotate-right", ); } $imagetools[] = array( "name" => "Flip horizontally", "action" => "cropReload('flipx');return false;", "icon" => "fas fa-fw fa-arrows-alt-h", ); $imagetools[] = array( "name" => "Flip vertically", "action" => "cropReload('flipy');return false;", "icon" => "fas fa-fw fa-arrows-alt-v", ); $imagetools[] = array( "name" => "Adjustments", "action" => "jQuery('.imagetools_actions').hide();jQuery('#croptools').show();jQuery('#imagetools_corrections_actions').show();return false;", "icon" => "fa fa-fw fa-sliders-h", ); hook("imagetools_extra"); ?>

0){ $orig_mptext = "($mp " . $lang["megapixel-short"] . ")"; } else { $orig_mptext = ''; } echo escape($lang['originalsize']) . ": "; echo escape($origwidth) . "x" . escape($origheight); echo " " . escape($lang['pixels']) . " $orig_mptext"; ?>

style="display: none;">
" onclick="postCrop(true);return false;" />
style="display: none;">