本文整理汇总了PHP中ewww_image_optimizer函数的典型用法代码示例。如果您正苦于以下问题:PHP ewww_image_optimizer函数的具体用法?PHP ewww_image_optimizer怎么用?PHP ewww_image_optimizer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ewww_image_optimizer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ewww_added_new_image
function ewww_added_new_image($image, $storage = null)
{
global $ewww_debug;
$ewww_debug .= "<b>ewww_added_new_image()</b><br>";
if (empty($storage)) {
// creating the 'registry' object for working with nextgen
$registry = C_Component_Registry::get_instance();
// creating a database storage object from the 'registry' object
$storage = $registry->get_utility('I_Gallery_Storage');
}
// find the image id
if (is_array($image)) {
$image_id = $image['id'];
$image = $storage->object->_image_mapper->find($image_id, TRUE);
} else {
$image_id = $storage->object->_get_image_id($image);
}
$ewww_debug .= "image id: {$image_id}<br>";
// get an array of sizes available for the $image
$sizes = $storage->get_image_sizes();
// run the optimizer on the image for each $size
foreach ($sizes as $size) {
if ($size === 'full') {
$full_size = true;
} else {
$full_size = false;
}
// get the absolute path
$file_path = $storage->get_image_abspath($image, $size);
$ewww_debug .= "optimizing (nextgen): {$file_path}<br>";
// optimize the image and grab the results
$res = ewww_image_optimizer($file_path, 2, false, false, $full_size);
$ewww_debug .= "results " . $res[1] . "<br>";
// only if we're dealing with the full-size original
if ($size === 'full') {
// update the metadata for the optimized image
$image->meta_data['ewww_image_optimizer'] = $res[1];
} else {
$image->meta_data[$size]['ewww_image_optimizer'] = $res[1];
}
nggdb::update_image_meta($image_id, $image->meta_data);
$ewww_debug .= 'storing results for full size image<br>';
}
ewww_image_optimizer_debug_log();
return $image;
}
示例2: ewww_image_optimizer_bulk_next
function ewww_image_optimizer_bulk_next($delay, $attachments)
{
// toggle the resume flag to indicate an operation is in progress
update_option('ewww_image_optimizer_bulk_ngg_resume', 'true');
// need this file to work with metadata
require_once WP_CONTENT_DIR . '/plugins/nextcellent-gallery-nextgen-legacy/lib/meta.php';
foreach ($attachments as $id) {
sleep($delay);
// find out what time we started, in microseconds
$started = microtime(true);
// get the metadata
$meta = new nggMeta($id);
// retrieve the filepath
$file_path = $meta->image->imagePath;
// run the optimizer on the current image
$fres = ewww_image_optimizer($file_path, 2, false, false, true);
// update the metadata of the optimized image
nggdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1]));
// output the results of the optimization
WP_CLI::line(__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . $meta->image->filename);
WP_CLI::line(sprintf(__('Full size - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($fres[1])));
// get the filepath of the thumbnail image
$thumb_path = $meta->image->thumbPath;
// run the optimization on the thumbnail
$tres = ewww_image_optimizer($thumb_path, 2, false, true);
// output the results of the thumb optimization
WP_CLI::line(sprintf(__('Thumbnail - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($tres[1])));
// outupt how much time we spent
$elapsed = microtime(true) - $started;
WP_CLI::line(sprintf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN), $elapsed));
// get the list of attachments remaining from the db
$attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments');
// remove the first item
if (!empty($attachments)) {
array_shift($attachments);
}
// and store the list back in the db
update_option('ewww_image_optimizer_bulk_ngg_attachments', $attachments, false);
}
// reset all the bulk options in the db
update_option('ewww_image_optimizer_bulk_ngg_resume', '');
update_option('ewww_image_optimizer_bulk_ngg_attachments', '', false);
// and let the user know we are done
WP_CLI::success(__('Finished Optimization!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
示例3: ewww_flag_bulk_loop
function ewww_flag_bulk_loop()
{
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) {
wp_die(__('Cheatin’ eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
if (!empty($_REQUEST['sleep'])) {
sleep($_REQUEST['sleep']);
}
// need this file to work with flag meta
require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
// record the starting time for the current image (in microseconds)
$started = microtime(true);
$id = $_POST['attachment'];
// get the image meta for the current ID
$meta = new flagMeta($id);
$file_path = $meta->image->imagePath;
// optimize the full-size version
$fres = ewww_image_optimizer($file_path, 3, false, false, ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_skip_full'));
$meta->image->meta_data['ewww_image_optimizer'] = $fres[1];
// let the user know what happened
printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename));
printf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $fres[1]);
$thumb_path = $meta->image->thumbPath;
// optimize the thumbnail
$tres = ewww_image_optimizer($thumb_path, 3, false, true);
$meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
// and let the user know the results
printf(__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $tres[1]);
flagdb::update_image_meta($id, $meta->image->meta_data);
// determine how much time the image took to process
$elapsed = microtime(true) - $started;
// and output it to the user
printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
// retrieve the list of attachments left to work on
$attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
// take the first image off the list
if (!empty($attachments)) {
array_shift($attachments);
}
// and send the list back to the db
update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments);
die;
}
示例4: ewww_flag_bulk_loop
function ewww_flag_bulk_loop()
{
global $ewww_defer;
$ewww_defer = false;
$output = array();
$permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
$output['error'] = esc_html__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
echo json_encode($output);
die;
}
session_write_close();
// find out if our nonce is on it's last leg/tick
$tick = wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk');
if ($tick === 2) {
$output['new_nonce'] = wp_create_nonce('ewww-image-optimizer-bulk');
} else {
$output['new_nonce'] = '';
}
// need this file to work with flag meta
require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
// record the starting time for the current image (in microseconds)
$started = microtime(true);
// retrieve the list of attachments left to work on
$attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
$id = array_shift($attachments);
// get the image meta for the current ID
$meta = new flagMeta($id);
$file_path = $meta->image->imagePath;
// optimize the full-size version
$fres = ewww_image_optimizer($file_path, 3, false, false, true);
$ewww_status = get_transient('ewww_image_optimizer_cloud_status');
if (!empty($ewww_status) && preg_match('/exceeded/', $ewww_status)) {
$output['error'] = esc_html__('License Exceeded', EWWW_IMAGE_OPTIMIZER_DOMAIN);
echo json_encode($output);
die;
}
$meta->image->meta_data['ewww_image_optimizer'] = $fres[1];
// let the user know what happened
$output['results'] = sprintf("<p>" . esc_html__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename));
$output['results'] .= sprintf(esc_html__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($fres[1]));
if (!empty($meta->image->meta_data['webview'])) {
// determine path of the webview
$web_path = $meta->image->webimagePath;
$wres = ewww_image_optimizer($web_path, 3, false, true);
$meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1];
$output['results'] .= sprintf(esc_html__('Optimized size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($wres[1]));
}
$thumb_path = $meta->image->thumbPath;
// optimize the thumbnail
$tres = ewww_image_optimizer($thumb_path, 3, false, true);
$meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
// and let the user know the results
$output['results'] .= sprintf(esc_html__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($tres[1]));
flagdb::update_image_meta($id, $meta->image->meta_data);
// determine how much time the image took to process
$elapsed = microtime(true) - $started;
// and output it to the user
$output['results'] .= sprintf(esc_html__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
// send the list back to the db
update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments, false);
if (!empty($attachments)) {
$next_attachment = array_shift($attachments);
$next_file = $this->ewww_flag_bulk_filename($next_attachment);
$loading_image = plugins_url('/images/wpspin.gif', __FILE__);
if ($next_file) {
$output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <b>{$next_file}</b> <img src='{$loading_image}' alt='loading'/></p>";
} else {
$output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <img src='{$loading_image}' alt='loading'/></p>";
}
}
echo json_encode($output);
die;
}
示例5: wppa_optimize_image_file
function wppa_optimize_image_file($file)
{
if (!wppa_switch('optimize_new')) {
return;
}
if (function_exists('ewww_image_optimizer')) {
ewww_image_optimizer($file, 4, false, false, false);
}
}
示例6: ewww_ngg_optimize
function ewww_ngg_optimize($id)
{
// retrieve the metadata for the image
$meta = new nggMeta($id);
// retrieve the image path
$file_path = $meta->image->imagePath;
// run the optimizer on the current image
$fres = ewww_image_optimizer($file_path, 2, false, false, true);
// update the metadata for the optimized image
nggdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1]));
// get the filepath of the thumbnail image
$thumb_path = $meta->image->thumbPath;
// run the optimization on the thumbnail
$tres = ewww_image_optimizer($thumb_path, 2, false, true);
return array($fres, $tres);
}
示例7: ewww_flag_bulk_loop
function ewww_flag_bulk_loop()
{
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) {
wp_die(__('Cheatin’ eh?'));
}
// need this file to work with flag meta
require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
// record the starting time for the current image (in microseconds)
$started = microtime(true);
$id = $_POST['attachment'];
// get the image meta for the current ID
$meta = new flagMeta($id);
$file_path = $meta->image->imagePath;
// optimize the full-size version
$fres = ewww_image_optimizer($file_path, 3, false, false);
// and store the results in the metadata
flagdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1]));
// let the user know what happened
printf("<p>Optimized image: <strong>%s</strong><br>", esc_html($meta->image->filename));
printf("Full size – %s<br>", $fres[1]);
$thumb_path = $meta->image->thumbPath;
// optimize the thumbnail
$tres = ewww_image_optimizer($thumb_path, 3, false, true);
// and let the user know the results
printf("Thumbnail – %s<br>", $tres[1]);
// determine how much time the image took to process
$elapsed = microtime(true) - $started;
// and output it to the user
echo "Elapsed: " . round($elapsed, 3) . " seconds</p>";
// retrieve the list of attachments left to work on
$attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
// take the first image off the list
array_shift($attachments);
// and send the list back to the db
update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments);
die;
}
示例8: handle
protected function handle()
{
session_write_close();
if (empty($_POST['ewwwio_size'])) {
$size = '';
} else {
$size = $_POST['ewwwio_size'];
}
if (!empty($_POST['ewwwio_path']) && $size == 'full') {
$file_path = $this->find_file($_POST['ewwwio_path']);
if (!empty($file_path)) {
ewwwio_debug_message('processing async optimization request');
list($file, $msg, $conv, $original) = ewww_image_optimizer($file_path, 1, false, false, true);
} else {
ewwwio_debug_message("could not process async optimization request for {$_POST['ewwwio_path']}");
}
} elseif (!empty($_POST['ewwwio_path'])) {
$file_path = $this->find_file($_POST['ewwwio_path']);
if (!empty($file_path)) {
ewwwio_debug_message('processing async optimization request');
list($file, $msg, $conv, $original) = ewww_image_optimizer($file_path);
} else {
ewwwio_debug_message("could not process async optimization request for {$_POST['ewwwio_path']}");
}
} else {
ewwwio_debug_message('ignored async optimization request');
return;
}
ewww_image_optimizer_hidpi_optimize($file_path);
ewwwio_debug_message('checking for: ' . $file_path . '.processing');
if (is_file($file_path . '.processing')) {
ewwwio_debug_message('removing ' . $file_path . '.processing');
unlink($file_path . '.processing');
}
ewww_image_optimizer_debug_log();
}
示例9: generate_image_size
function generate_image_size($image, $size, $params = null, $skip_defaults = false)
{
global $ewww_debug;
if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
ewww_image_optimizer_init();
}
$success = $this->call_parent('generate_image_size', $image, $size, $params, $skip_defaults);
if ($success) {
//$filename = $this->object->get_image_abspath($image, $size);
$filename = $success->fileName;
ewww_image_optimizer($filename);
// ewww_image_optimizer_aux_images_loop( $filename, true );
$ewww_debug .= "nextgen dynamic thumb saved: {$filename} <br>";
$image_size = filesize($filename);
$ewww_debug .= "optimized size: {$image_size} <br>";
}
ewww_image_optimizer_debug_log();
ewwwio_memory(__FUNCTION__);
return $success;
}
示例10: ewww_flag_bulk_loop
function ewww_flag_bulk_loop()
{
global $ewww_defer;
$ewww_defer = false;
$permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
wp_die(__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
if (!empty($_REQUEST['ewww_sleep'])) {
sleep($_REQUEST['ewww_sleep']);
}
// need this file to work with flag meta
require_once WP_CONTENT_DIR . '/plugins/flash-album-gallery/lib/meta.php';
// record the starting time for the current image (in microseconds)
$started = microtime(true);
$id = $_POST['ewww_attachment'];
// get the image meta for the current ID
$meta = new flagMeta($id);
$file_path = $meta->image->imagePath;
// optimize the full-size version
$fres = ewww_image_optimizer($file_path, 3, false, false, true);
global $ewww_exceed;
if (!empty($ewww_exceed)) {
echo '-9exceeded';
die;
}
$meta->image->meta_data['ewww_image_optimizer'] = $fres[1];
// let the user know what happened
printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta->image->filename));
printf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $fres[1]);
if (!empty($meta->image->meta_data['webview'])) {
// determine path of the webview
$web_path = $meta->image->webimagePath;
$wres = ewww_image_optimizer($web_path, 3, false, true);
$meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1];
printf(__('Optimized size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $wres[1]);
}
$thumb_path = $meta->image->thumbPath;
// optimize the thumbnail
$tres = ewww_image_optimizer($thumb_path, 3, false, true);
$meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
// and let the user know the results
printf(__('Thumbnail – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $tres[1]);
flagdb::update_image_meta($id, $meta->image->meta_data);
// determine how much time the image took to process
$elapsed = microtime(true) - $started;
// and output it to the user
printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
// retrieve the list of attachments left to work on
$attachments = get_option('ewww_image_optimizer_bulk_flag_attachments');
// take the first image off the list
if (!empty($attachments)) {
array_shift($attachments);
}
// and send the list back to the db
update_option('ewww_image_optimizer_bulk_flag_attachments', $attachments);
die;
}
示例11: flickr_image_attach_deprecated
function flickr_image_attach_deprecated($flickrurl, $post_id)
{
preg_match('/http\\:\\/\\/www\\.flickr\\.com\\/photos\\/(.*?)\\/([0-9]+)\\//si', $flickrurl, $m);
if ($m) {
$flickruser = $m[1];
$photo_id = $m[2];
} else {
return;
}
//$flickruser = getFlickrUser($photo_id);
$file = getFlickrURL($photo_id);
if (!empty($file)) {
// Download file to temp location
$tmp = download_url($file);
// Set variables for storage
// fix file filename for query strings
preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $file, $matches);
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
// If error storing temporarily, unlink
if (is_wp_error($tmp)) {
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
// do the validation and storage stuff
$id = media_handle_sideload($file_array, $post_id, $desc = null);
// If error storing permanently, unlink
if (is_wp_error($id)) {
@unlink($file_array['tmp_name']);
return $id;
}
$fullsize_path = get_attached_file($id);
// Full path
if (function_exists('ewww_image_optimizer')) {
ewww_image_optimizer($fullsize_path, $gallery_type = 4, $converted = false, $new = true, $fullsize = true);
}
$src = wp_get_attachment_url($id);
}
if (!empty($src)) {
update_post_meta($post_id, 'image_url_value', $flickrurl);
update_post_meta($post_id, 'image_author_t_value', $flickruser);
update_post_meta($post_id, 'image_value', $src);
set_post_thumbnail($post_id, $id);
return update_post_meta($post_id, 'Thumbnail', $src);
} else {
return false;
}
}
示例12: ewww_ngg_bulk_loop
function ewww_ngg_bulk_loop()
{
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) {
wp_die(__('Cheatin’ eh?'));
}
// need this file to work with metadata
require_once WP_CONTENT_DIR . '/plugins/nextgen-gallery/lib/meta.php';
// find out what time we started, in microseconds
$started = microtime(true);
$id = $_POST['attachment'];
// get the metadata
$meta = new nggMeta($id);
// retrieve the filepath
$file_path = $meta->image->imagePath;
// run the optimizer on the current image
$fres = ewww_image_optimizer($file_path, 2, false, false);
// update the metadata of the optimized image
nggdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1]));
// output the results of the optimization
printf("<p>Optimized image: <strong>%s</strong><br>", $meta->image->filename);
printf("Full size - %s<br>", $fres[1]);
// get the filepath of the thumbnail image
$thumb_path = $meta->image->thumbPath;
// run the optimization on the thumbnail
$tres = ewww_image_optimizer($thumb_path, 2, false, true);
// output the results of the thumb optimization
printf("Thumbnail - %s<br>", $tres[1]);
// outupt how much time we spent
$elapsed = microtime(true) - $started;
echo "Elapsed: " . round($elapsed, 3) . " seconds</p>";
// get the list of attachments remaining from the db
$attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments');
// remove the first item
array_shift($attachments);
// and store the list back in the db
update_option('ewww_image_optimizer_bulk_ngg_attachments', $attachments);
die;
}
示例13: ewww_image_optimizer_resize_from_meta_data
/**
* Read the image paths from an attachment's meta data and process each image
* with ewww_image_optimizer().
*
* This method also adds a `ewww_image_optimizer` meta key for use in the media library
* and may add a 'converted' and 'orig_file' key if conversion is enabled.
*
* Called after `wp_generate_attachment_metadata` is completed.
*/
function ewww_image_optimizer_resize_from_meta_data($meta, $ID = null, $log = true, $background_new = false)
{
ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
if (!is_array($meta) && empty($meta)) {
$meta = array();
} elseif (!is_array($meta)) {
if (is_string($meta) && is_int($ID) && 'processing' == $meta) {
ewwwio_debug_message("attempting to rebuild attachment meta for {$ID}");
$new_meta = ewww_image_optimizer_rebuild_meta($ID);
if (!is_array($new_meta)) {
ewwwio_debug_message('attempt to rebuild attachment meta failed');
return $meta;
} else {
$meta = $new_meta;
}
} else {
ewwwio_debug_message('attachment meta is not a usable array');
return $meta;
}
} elseif (is_array($meta) && !empty($meta[0]) && 'processing' == $meta[0]) {
ewwwio_debug_message("attempting to rebuild attachment meta for {$ID}");
$new_meta = ewww_image_optimizer_rebuild_meta($ID);
if (!is_array($new_meta)) {
ewwwio_debug_message('attempt to rebuild attachment meta failed');
return $meta;
} else {
$meta = $new_meta;
}
}
global $wpdb;
global $ewww_defer;
global $ewww_new_image;
$gallery_type = 1;
ewwwio_debug_message("attachment id: {$ID}");
session_write_close();
//if ( ! metadata_exists( 'post', $ID, '_wp_attachment_metadata' ) ) {
if (!empty($ewww_new_image)) {
ewwwio_debug_message('this is a newly uploaded image with no metadata yet');
$new_image = true;
} else {
ewwwio_debug_message('this image already has metadata, so it is not new');
$new_image = false;
}
list($file_path, $upload_path) = ewww_image_optimizer_attachment_path($meta, $ID);
// if the attachment has been uploaded via the image store plugin
if ('ims_image' == get_post_type($ID)) {
$gallery_type = 6;
}
if (!$new_image && class_exists('Amazon_S3_And_CloudFront') && strpos($file_path, 's3') === 0) {
ewww_image_optimizer_check_table_as3cf($meta, $ID, $file_path);
}
// if the local file is missing and we have valid metadata, see if we can fetch via CDN
if (!is_file($file_path) || strpos($file_path, 's3') === 0) {
$file_path = ewww_image_optimizer_remote_fetch($ID, $meta);
if (!$file_path) {
ewwwio_debug_message('could not retrieve path');
$meta['ewww_image_optimizer'] = __('Could not find image', EWWW_IMAGE_OPTIMIZER_DOMAIN);
return $meta;
}
}
ewwwio_debug_message("retrieved file path: {$file_path}");
$type = ewww_image_optimizer_mimetype($file_path, 'i');
$supported_types = array('image/jpeg', 'image/png', 'image/gif', 'application/pdf');
if (!in_array($type, $supported_types)) {
ewwwio_debug_message("mimetype not supported: {$ID}");
return $meta;
}
// see if this is a new image and Imsanity resized it (which means it could be already optimized)
if (!empty($new_image) && function_exists('imsanity_get_max_width_height')) {
list($maxW, $maxH) = imsanity_get_max_width_height(IMSANITY_SOURCE_LIBRARY);
list($oldW, $oldH) = getimagesize($file_path);
list($newW, $newH) = wp_constrain_dimensions($oldW, $oldH, $maxW, $maxH);
$path_parts = pathinfo($file_path);
$imsanity_path = trailingslashit($path_parts['dirname']) . $path_parts['filename'] . '-' . $newW . 'x' . $newH . '.' . $path_parts['extension'];
ewwwio_debug_message("imsanity path: {$imsanity_path}");
$image_size = ewww_image_optimizer_filesize($file_path);
$already_optimized = ewww_image_optimizer_find_already_optimized($imsanity_path);
if (is_array($already_optimized)) {
ewwwio_debug_message("updating existing record, path: {$file_path}, size: " . $image_size);
// store info on the current image for future reference
$wpdb->update($wpdb->ewwwio_images, array('path' => $file_path), array('id' => $already_optimized['id']));
}
}
if ((!empty($new_image) || ewww_image_optimizer_get_option('ewww_image_optimizer_resize_existing')) && !function_exists('imsanity_get_max_width_height')) {
$new_dimensions = ewww_image_optimizer_resize_upload($file_path);
if (is_array($new_dimensions)) {
$meta['width'] = $new_dimensions[0];
$meta['height'] = $new_dimensions[1];
}
}
if ($ewww_defer && !ewww_image_optimizer_detect_wpsf_location_lock()) {
//.........这里部分代码省略.........
示例14: ewww_image_optimizer_resize_from_meta_data
/**
* Read the image paths from an attachment's meta data and process each image
* with ewww_image_optimizer().
*
* This method also adds a `ewww_image_optimizer` meta key for use in the media library
* and may add a 'converted' and 'orig_file' key if conversion is enabled.
*
* Called after `wp_generate_attachment_metadata` is completed.
*/
function ewww_image_optimizer_resize_from_meta_data($meta, $ID = null)
{
global $ewww_debug;
$ewww_debug = "{$ewww_debug} <b>ewww_image_optimizer_resize_from_meta_data()</b><br>";
// don't do anything else if the attachment has no metadata
if (!isset($meta['file'])) {
$ewww_debug = "{$ewww_debug} file has no meta<br>";
return $meta;
}
if (FALSE === has_filter('wp_update_attachment_metadata', 'ewww_image_optimizer_update_saved_file')) {
$gallery_type = 1;
} else {
$gallery_type = 5;
}
// get the filepath from the metadata
$file_path = $meta['file'];
$ewww_debug = "{$ewww_debug} meta file path: {$file_path}<br>";
// store absolute paths for older wordpress versions
$store_absolute_path = true;
// retrieve the location of the wordpress upload folder
$upload_dir = wp_upload_dir();
// retrieve the path of the upload folder
$upload_path = trailingslashit($upload_dir['basedir']);
// if the path given is not the absolute path
if (FALSE == file_exists($file_path)) {
// don't store absolute paths
$store_absolute_path = false;
// generate the absolute path
$file_path = $upload_path . $file_path;
$ewww_debug = "{$ewww_debug} generated absolute path: {$file_path}<br>";
}
// run the image optimizer on the file, and store the results
list($file, $msg, $conv, $original) = ewww_image_optimizer($file_path, $gallery_type, false, false);
// update the filename in the metadata
$meta['file'] = $file;
// update the optimization results in the metadata
$meta['ewww_image_optimizer'] = $msg;
// strip absolute path for Wordpress >= 2.6.2
if (FALSE === $store_absolute_path) {
$meta['file'] = str_replace($upload_path, '', $meta['file']);
}
// if the file was converted
if ($conv) {
$ewww_debug = "{$ewww_debug} image was converted<br>";
// if we don't already have the update attachment filter
if (FALSE === has_filter('wp_update_attachment_metadata', 'ewww_image_optimizer_update_attachment')) {
// add the update attachment filter
add_filter('wp_update_attachment_metadata', 'ewww_image_optimizer_update_attachment', 10, 2);
}
// store the conversion status in the metadata
$meta['converted'] = 1;
// store the old filename in the database
$meta['orig_file'] = $original;
} else {
remove_filter('wp_update_attachment_metadata', 'ewww_image_optimizer_update_attachment', 10);
}
// resized versions, so we can continue
if (isset($meta['sizes'])) {
$ewww_debug = "{$ewww_debug} processing resizes<br>";
// meta sizes don't contain a path, so we calculate one
$base_dir = dirname($file_path) . '/';
// process each resized version
$processed = array();
foreach ($meta['sizes'] as $size => $data) {
// initialize $dup_size
$dup_size = false;
// check through all the sizes we've processed so far
foreach ($processed as $proc => $scan) {
// if a previous resize had identical dimensions
if ($scan['height'] == $data['height'] && $scan['width'] == $data['width']) {
// found a duplicate resize
$dup_size = true;
// point this resize at the same image as the previous one
$meta['sizes'][$size]['file'] = $meta['sizes'][$proc]['file'];
// and tell the user we didn't do any further optimization
$meta['sizes'][$size]['ewww_image_optimizer'] = 'No savings';
}
}
// if this is a unique size
if (!$dup_size) {
// run the optimization and store the results
list($optimized_file, $results, $resize_conv, $original) = ewww_image_optimizer($base_dir . $data['file'], $gallery_type, $conv, true);
// if the resize was converted, store the result and the original filename in the metadata for later recovery
if ($resize_conv) {
// if we don't already have the update attachment filter
if (FALSE === has_filter('wp_update_attachment_metadata', 'ewww_image_optimizer_update_attachment')) {
// add the update attachment filter
add_filter('wp_update_attachment_metadata', 'ewww_image_optimizer_update_attachment', 10, 2);
}
$meta['sizes'][$size]['converted'] = 1;
$meta['sizes'][$size]['orig_file'] = str_replace($base_dir, '', $original);
//.........这里部分代码省略.........
示例15: generate_image_size
function generate_image_size($image, $size, $params = null, $skip_defaults = false)
{
ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
global $ewww_defer;
if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
ewww_image_optimizer_init();
}
$success = $this->call_parent('generate_image_size', $image, $size, $params, $skip_defaults);
if ($success) {
$filename = $success->fileName;
if ($ewww_defer && ewww_image_optimizer_get_option('ewww_image_optimizer_defer')) {
ewww_image_optimizer_add_deferred_attachment("file,{$filename}");
return $saved;
}
ewww_image_optimizer($filename);
ewwwio_debug_message("nextgen dynamic thumb saved: {$filename}");
$image_size = ewww_image_optimizer_filesize($filename);
ewwwio_debug_message("optimized size: {$image_size}");
}
ewww_image_optimizer_debug_log();
ewwwio_memory(__FUNCTION__);
return $success;
}