0, 'height' => 0); } $sizes = get_all_image_sizes(); $found_idx = array_search($size, array_column($sizes, 'id')); if($found_idx === false) { die('Unknown size: "' . escape($size) . '"'); } return [ 'width' => $sizes[$found_idx]['width'], 'height' => $sizes[$found_idx]['height'], ]; } /** * Converts the file of the given resource to the new target file with the specified size. The * target file format is determined from the suffix of the target file. * The original colorspace of the image is retained. If $width and $height are zero, the image * keeps its original size. */ function convertImage($resource, $page, $alternative, $target, $width, $height, $profile) { global $exiftool_write, $exiftool_write_option, $username, $scramble_key, $preview_no_flatten_extensions; $requested_extension = $resource['file_extension']; # If downloading alternative file, lookup its file extension before preparing resource path as it may differ from the resource. if ($alternative > 0) { $alt_file = get_alternative_file($resource['ref'], $alternative); $requested_extension = $alt_file['file_extension']; } $originalPath = get_resource_path($resource['ref'], true, '', false, $requested_extension, -1, $page, false, '', $alternative); if($exiftool_write && $exiftool_write_option) { $randstring=md5(rand() . microtime()); $target_temp_id = $resource['ref'] . "_" . md5($username . $randstring . $scramble_key); $path = write_metadata($originalPath, $resource['ref'], "format_chooser/" . $target_temp_id); //$temp_path for removal later to assure not removing original path $temp_path = get_temp_dir(false,"format_chooser/" . $resource['ref'] . "_" . md5($username . $randstring . $scramble_key)); } else { $path = $originalPath; } $transform_actions = [ 'tfactions' => [], 'resize' => ['width' => $width, 'height' => $height], 'auto_orient' => null, ]; // Preserve transparency like background for conversion from eps files (transparency is not supported in jpg file type). if ($resource['file_extension'] == "eps") { $transform_actions['transparent'] = ''; } // Handle alpha/ matte channels $target_extension = pathinfo($target, PATHINFO_EXTENSION); if(!in_array(strtolower($target_extension), $preview_no_flatten_extensions)) { $transform_actions['background'] = 'white'; } if($profile === '') { $transform_actions['profile'][] = ['strip' => true, 'path' => '*']; } elseif(!empty($profile)) { // Find out if the image does already have a profile $identify = get_utility_path("im-identify"); $info = run_command( "{$identify} -verbose path", false, [ 'path' => new CommandPlaceholderArg($path, 'is_valid_rs_path'), ] ); $basePath = dirname(__FILE__, 4) . '/'; if(preg_match("/Profile-icc:/", $info) != 1) { $transform_actions['profile'][] = ['strip' => false, 'path' => $basePath . 'iccprofiles/sRGB_IEC61966-2-1_black_scaled.icc']; } $transform_actions['profile'][] = ['strip' => false, 'path' => $basePath . $profile]; } $transform_actions = array_merge($transform_actions, transform_apply_icc_profile($resource['ref'], $originalPath)); if (!transform_file($path, $target, $transform_actions)) { debug('Unable to transform file!'); return false; } //remove temp once completed if(isset($temp_path)) { rcRmdir($temp_path); } } function sendFile($filename, string $download_filename, $usage = -1, $usagecomment = "") { $suffix = pathinfo($filename, PATHINFO_EXTENSION); global $baseurl, $username, $scramble_key, $exiftool_write; list($resource_ref, $download_key) = explode('_', pathinfo($filename, PATHINFO_FILENAME)); $user_downloads_path = sprintf('%s/%s_%s.%s', get_temp_dir(false, 'user_downloads'), $resource_ref, md5($username . $download_key . $scramble_key), $suffix ); copy($filename, $user_downloads_path); $user_download_url = generateURL( $baseurl . '/pages/download.php', [ 'userfile' => pathinfo($filename, PATHINFO_BASENAME), 'filename' => strip_extension($download_filename, false), 'usage' => $usage, 'usagecomment' => $usagecomment, 'k' => getval('k', ''), 'ref' => getval('ref', ''), 'exif_write' => ($exiftool_write ? 'true' : '') ] ); redirect($user_download_url); } /** * Show colour profile selector based on $format_chooser_profiles config * * @param string $class CSS class for select * @param string $disabledtext Text to disable and hide inputs * @param string $ns Select ID * */ function showProfileChooser(string $class = '', string $disabledtext = '', string $ns = ''): void { global $format_chooser_profiles, $lang; if (empty($format_chooser_profiles)) { return; } ?>