function aux_image($value, $params, $type = NULL) { $md5_params = md5($params); $thumb_path = MF_CACHE_DIR . 'th_' . $md5_params . "_" . $value; $thumb_url = MF_CACHE_URL . 'th_' . $md5_params . "_" . $value; $image_path = MF_FILES_DIR . $value; $name_image = $value; if ($type == 'image_media') { $data = preg_split('/\\//', $value); $thumb_path = MF_CACHE_DIR . 'th_' . $md5_params . "_" . $data[count($data) - 1]; $thumb_url = MF_CACHE_URL . 'th_' . $md5_params . "_" . $data[count($data) - 1]; $image_path = str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $value); $name_image = $data[count($data) - 1]; } if (file_exists($thumb_path)) { $value = $thumb_url; } else { //generate thumb $create_md5_filename = 'th_' . $md5_params . "_" . $name_image; $output_filename = MF_CACHE_DIR . $create_md5_filename; $final_filename = MF_CACHE_URL . $create_md5_filename; $default = array('zc' => 1, 'w' => 0, 'h' => 0, 'q' => 85, 'src' => $image_path, 'far' => false, 'iar' => false); $size = @getimagesize($image_path); $defaults['w'] = $size[0]; $defaults['h'] = $size[1]; $params_image = explode("&", $params); foreach ($params_image as $param) { if ($param) { $p_image = explode("=", $param); $default[$p_image[0]] = $p_image[1]; } } if ($default['w'] > 0 && $default['h'] == 0) { $default['h'] = round($default['w'] * $defaults['h'] / $defaults['w']); } elseif ($default['w'] == 0 && $default['h'] > 0) { $default['w'] = round($default['h'] * $defaults['w'] / $defaults['h']); } $MFthumb = MF_PATH . '/MF_thumb.php'; require_once $MFthumb; $thumb = new mfthumb(); $thumb_path = $thumb->image_resize($default['src'], $default['w'], $default['h'], $default['zc'], $default['far'], $default['iar'], $output_filename, $default['q']); if (is_wp_error($thumb_path)) { return $thumb_path->get_error_message(); } $value = $final_filename; } return $value; }
$size = getimagesize(MF_CACHE_DIR . $image_name); $handle = fopen(MF_CACHE_DIR . $image_name, "rb"); $contents = NULL; while (!feof($handle)) { $contents .= fread($handle, 1024); } fclose($handle); header("Cache-Control: public"); header("Content-type: image/" . $extension); header("Content-Disposition: inline; filename=\"" . MF_CACHE_DIR . $image_name . "\""); header('Content-Length: ' . filesize(MF_CACHE_DIR . $image_name)); echo $contents; } else { //generating the image $thumb = new mfthumb(); $thumb_path = $thumb->image_resize(MF_UPLOAD_FILES_DIR . $image_name_clean, $params['w'], $params['h'], $params['zc'], MF_CACHE_DIR . $image_name); //Displaying the image if (file_exists($thumb_path)) { $size = getimagesize($thumb_path); $handle = fopen($thumb_path, "rb"); $contents = NULL; while (!feof($handle)) { $contents .= fread($handle, filesize($thumb_path)); } fclose($handle); header("Cache-Control: public"); header("Content-type: image/" . $extension); header("Content-Disposition: inline; filename=\"" . $thumb_path . "\""); header('Content-Length: ' . filesize($thumb_path)); echo $contents; }
$size = getimagesize(MF_CACHE_DIR . $image_name); $handle = fopen(MF_CACHE_DIR . $image_name, "rb"); $contents = NULL; while (!feof($handle)) { $contents .= fread($handle, 1024); } fclose($handle); header("Cache-Control: public"); header("Content-type: image/" . $extension); header("Content-Disposition: inline; filename=\"" . MF_CACHE_DIR . $image_name . "\""); header('Content-Length: ' . filesize(MF_CACHE_DIR . $image_name)); echo $contents; } else { //generating the image $thumb = new mfthumb(); $thumb_path = $thumb->image_resize($file, $params['w'], $params['h'], $params['zc'], $params['far'], $params['iar'], MF_CACHE_DIR . $image_name); //Displaying the image if (file_exists($thumb_path)) { $size = getimagesize($thumb_path); $handle = fopen($thumb_path, "rb"); $contents = NULL; while (!feof($handle)) { $contents .= fread($handle, filesize($thumb_path)); } fclose($handle); header("Cache-Control: public"); header("Content-type: image/" . $extension); header("Content-Disposition: inline; filename=\"" . $thumb_path . "\""); header('Content-Length: ' . filesize($thumb_path)); echo $contents; }
function aux_image($fieldValue, $params_image) { $md5_params = md5($params_image); if (file_exists(MF_CACHE_DIR . 'th_' . $md5_params . "_" . $fieldValue)) { $fieldValue = MF_CACHE_URI . 'th_' . $md5_params . "_" . $fieldValue; } else { //generate thumb $create_md5_filename = 'th_' . $md5_params . "_" . $fieldValue; $output_filename = MF_CACHE_DIR . $create_md5_filename; $final_filename = MF_CACHE_URI . $create_md5_filename; $default = array('zc' => 1, 'w' => 100, 'h' => 100, 'q' => 85, 'src' => MF_FILES_PATH . $fieldValue); $size = @getimagesize(MF_UPLOAD_FILES_DIR . $fieldValue); $default['w'] = $size[0]; $default['h'] = $size[1]; $params_image = explode("&", $params_image); foreach ($params_image as $param) { if ($param) { $p_image = explode("=", $param); $default[$p_image[0]] = $p_image[1]; } } $MFthumb = MF_PATH . '/MF_thumb.php'; require_once $MFthumb; $thumb = new mfthumb(); $thumb_path = $thumb->image_resize($default['src'], $default['w'], $default['h'], $default['zc'], $output_filename, $default['q']); if (is_wp_error($thumb_path)) { return $thumb_path->get_error_message(); } $fieldValue = $final_filename; } return $fieldValue; }
function aux_image($fieldValue, $params_image, $fieldType = NULL) { $md5_params = md5($params_image); $thumb_path = MF_CACHE_DIR . 'th_' . $md5_params . "_" . $fieldValue; $thumb_url = MF_CACHE_URI . 'th_' . $md5_params . "_" . $fieldValue; $image_path = MF_UPLOAD_FILES_DIR . $fieldValue; $name_image = $fieldValue; if ($fieldType == 16) { $data = preg_split('/\\//', $fieldValue); $thumb_path = MF_CACHE_DIR . 'th_' . $md5_params . "_" . $data[count($data) - 1]; $thumb_url = MF_CACHE_URI . 'th_' . $md5_params . "_" . $data[count($data) - 1]; $image_path = str_replace(WP_CONTENT_URL . DIRECTORY_SEPARATOR, MF_WPCONTENT, $fieldValue); $name_image = $data[count($data) - 1]; } $exists = file_exists($thumb_path); list($exists, $thumb_url) = apply_filters('mf_source_path_thumb_image', array($exists, $thumb_url)); if ($exists) { $fieldValue = $thumb_url; } else { //generate thumb $create_md5_filename = 'th_' . $md5_params . "_" . $name_image; $output_filename = MF_CACHE_DIR . $create_md5_filename; $final_filename = MF_CACHE_URI . $create_md5_filename; do_action('mf_before_generate_thumb', $image_path); $default = array('zc' => 1, 'w' => 0, 'h' => 0, 'q' => 85, 'src' => $image_path, 'far' => false, 'iar' => false); $size = @getimagesize($image_path); $defaults['w'] = $size[0]; $defaults['h'] = $size[1]; $params_image = explode("&", $params_image); foreach ($params_image as $param) { if ($param) { $p_image = explode("=", $param); $default[$p_image[0]] = $p_image[1]; } } if ($default['w'] > 0 && $default['h'] == 0) { $default['h'] = round($default['w'] * $defaults['h'] / $defaults['w']); } elseif ($default['w'] == 0 && $default['h'] > 0) { $default['w'] = round($default['h'] * $defaults['w'] / $defaults['h']); } $MFthumb = MF_PATH . '/MF_thumb.php'; require_once $MFthumb; $thumb = new mfthumb(); $thumb_path = $thumb->image_resize($default['src'], $default['w'], $default['h'], $default['zc'], $default['far'], $default['iar'], $output_filename, $default['q']); if (is_wp_error($thumb_path)) { return $thumb_path->get_error_message(); } $fieldValue = $final_filename; list($tm_width, $tm_height, $tm_type, $tm_attr) = getimagesize($output_filename); $file = array('tmp_name' => $output_filename, 'size' => filesize($output_filename), 'type' => $tm_type); do_action('mf_after_upload_file', $file); do_action('mf_save_thumb_file', $final_filename); $fieldValue = apply_filters('mf_source_image', $fieldValue); } return $fieldValue; }