function file_gallery_add_media_actions($actions, $post) { if (!isset($actions['sis-regenerate']) && !isset($action['regenerate_thumbnails']) && file_is_displayable_image(get_attached_file($post->ID))) { $actions['file_gallery_regenerate'] = '<a href="#" id="file_gallery_regenerate-' . $post->ID . '" class="file_gallery_regenerate">' . __('Regenerate', 'file-gallery') . '</a>'; } return $actions; }
function my_save_extra_profile_fields($user_id) { if (!current_user_can('edit_user', $user_id)) { return false; } $upload = $_FILES['profile_image']; $uploads = wp_upload_dir(); if ($upload['tmp_name'] && file_is_displayable_image($upload['tmp_name'])) { // handle the uploaded file $overrides = array('test_form' => false); $file = wp_handle_upload($upload, $overrides); $file["file"] = $uploads["subdir"] . "/" . basename($file["url"]); if ($file) { //remove previous uploaded file $author_profile_image = $this->get_author_profile_image($user_id); @unlink($author_profile_image["file"]); update_user_meta($user_id, 'profile_image', $file); } } if (isset($_POST['remove_image'])) { $author_profile_image = $this->get_author_profile_image($user_id); @unlink($author_profile_image["file"]); update_user_meta($user_id, 'profile_image', false); } }
/** * wp_generate_attachment_metadata() - Generate post Image attachment Metadata * * @package WordPress * @internal Missing Long Description * @param int $attachment_id Attachment Id to process * @param string $file Filepath of the Attached image * @return mixed Metadata for attachment * */ function wp_generate_attachment_metadata($attachment_id, $file) { $attachment = get_post($attachment_id); $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; $metadata['file'] = $file; // make thumbnails and other intermediate sizes $sizes = array('thumbnail', 'medium'); $sizes = apply_filters('intermediate_image_sizes', $sizes); foreach ($sizes as $size) { $resized = image_make_intermediate_size($file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop")); if ($resized) { $metadata['sizes'][$size] = $resized; } } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } return apply_filters('wp_generate_attachment_metadata', $metadata); }
public function wp_generate_attachment_metadata($metadata, $attachment_id) { $attachment = get_attached_file($attachment_id); if (!preg_match('!^image/!', get_post_mime_type($attachment_id)) || !file_is_displayable_image($attachment)) { return $metadata; } $image_sizes = Helper::get_image_sizes(); foreach ($image_sizes as $size_name => $size_attributes) { if (!empty($metadata['sizes'][$size_name])) { continue; } $image = wp_get_image_editor($attachment); if (is_wp_error($image)) { continue; } $resized = $image->resize($size_attributes['width'], $size_attributes['height'], $size_attributes['crop']); $image_size = $image->get_size(); if (!is_wp_error($resized) && !empty($image_size)) { $filename = wp_basename($image->generate_filename()); $extension = pathinfo($filename, PATHINFO_EXTENSION); $mime_type = $this->get_mime_type($extension); $metadata['sizes'][$size_name] = array('file' => $filename, 'width' => $image_size['width'], 'height' => $image_size['height'], 'mime-type' => $mime_type); } } return $metadata; }
function test_is_displayable_image_negative() { // these are image files but aren't suitable for web pages because of compatibility or size issues $files = array('test-image.pct', 'test-image.tga', 'test-image.sgi', 'test-image.tiff', 'test-image-lzw.tiff', 'test-image.jp2', 'test-image.psd', 'test-image-zip.tiff'); foreach ($files as $file) { $this->assertFalse(file_is_displayable_image(DIR_TESTDATA . '/images/' . $file), "file_is_valid_image({$file}) should return false"); } }
function sp_generate_attachment_metadata($attachment_id, $file) { $attachment = get_post($attachment_id); $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; // Make the file path relative to the upload dir $metadata['file'] = $attachment->post_title; // make thumbnails and other intermediate sizes global $_wp_additional_image_sizes; $temp_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes if (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes)) { $temp_sizes = array_merge($temp_sizes, array_keys($_wp_additional_image_sizes)); } $temp_sizes = apply_filters('intermediate_image_sizes', $temp_sizes); foreach ($temp_sizes as $s) { $sizes[$s] = array('width' => '', 'height' => '', 'crop' => FALSE); if (isset($_wp_additional_image_sizes[$s]['width'])) { $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']); } else { $sizes[$s]['width'] = get_option("{$s}_size_w"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['height'])) { $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']); } else { $sizes[$s]['height'] = get_option("{$s}_size_h"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['crop'])) { $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']); } else { $sizes[$s]['crop'] = get_option("{$s}_crop"); } // For default sizes set in options } $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes); foreach ($sizes as $size => $size_data) { $resized = image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']); if ($resized) { $metadata['sizes'][$size] = $resized; } } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); }
function hack_wp_generate_attachment_metadata($metadata, $attachment_id) { if (!isset($metadata['file'])) { return $metadata; } $attachment = get_post($attachment_id); $uploadPath = wp_upload_dir(); $file = path_join($uploadPath['basedir'], $metadata['file']); $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); // make thumbnails and other intermediate sizes global $_wp_additional_image_sizes; foreach (get_intermediate_image_sizes() as $s) { $sizes[$s] = array('width' => '', 'height' => '', 'crop' => FALSE); if (isset($_wp_additional_image_sizes[$s]['width'])) { $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']); } else { $sizes[$s]['width'] = get_option("{$s}_size_w"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['height'])) { $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']); } else { $sizes[$s]['height'] = get_option("{$s}_size_h"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['crop'])) { $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']); } else { $sizes[$s]['crop'] = get_option("{$s}_crop"); } // For default sizes set in options } foreach ($sizes as $size => $size_data) { $resized = hack_image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop'], $size); if ($resized) { $metadata['sizes'][$size] = $resized; } } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } return $metadata; }
/** * Generate post thumbnail attachment meta data. * * @since 2.1.0 * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. * @return mixed Metadata for attachment. */ function wp_generate_attachment_metadata( $attachment_id, $file ) { $attachment = get_post( $attachment_id ); $metadata = array(); if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { $imagesize = getimagesize( $file ); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); // make thumbnails and other intermediate sizes global $_wp_additional_image_sizes; foreach ( get_intermediate_image_sizes() as $s ) { $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false ); if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes else $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes else $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes else $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options } $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); if ( $sizes ) { $editor = wp_get_image_editor( $file ); if ( ! is_wp_error( $editor ) ) $metadata['sizes'] = $editor->multi_resize( $sizes ); } else { $metadata['sizes'] = array(); } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata( $file ); if ( $image_meta ) $metadata['image_meta'] = $image_meta; } return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id ); }
/** * Enforce Attachment Size * * @param array $data Sanitized post data. * @param array $postarr Raw post data. **/ public function enforce_attachment_size($data, $postarr) { // File path. $file = $postarr['file']; // Check if we are dealing with an attachment of type image. if ('attachment' === $data['post_type'] && preg_match('!^image/!', $postarr['post_mime_type']) && \file_is_displayable_image($file)) { $resize_dimensions = $this->resize_dimensions(); // Do the actual resize of the original attachment. if (!empty($resize_dimensions)) { $this->resize_original($postarr['file'], $resize_dimensions); } } return $data; }
/** * Detect file upload and handle it * * return void */ function mief_slideshow_detect_upload() { if (!empty($_FILES)) { global $wpdb; if (file_is_displayable_image($_FILES['mief_slideshow_file']['tmp_name'])) { $overrides = array('test_form' => false); $file = wp_handle_upload($_FILES['mief_slideshow_file'], $overrides); if ($file) { $table_name = $wpdb->prefix . "mief_slideshow"; $result = $wpdb->insert($table_name, array('filename' => serialize($file), 'url' => '', 'weight' => 1, 'slideshow_id' => mief_get_slideshow_mid())); } } } }
/** * generate attachment metadata but DO NOT create thumbnails etc. * @param int $attachment_id * @param string $file * absolute file path */ public static function generate_attachment_metadata($attachment_id, $file) { $attachment = get_post($attachment_id); $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); // work with some watermark plugin $metadata = apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); } return $metadata; }
/** * Generate post thumbnail attachment meta data. * * @since 2.1.0 * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. * @return mixed Metadata for attachment. */ function wp_generate_attachment_metadata_custom($attachment_id, $file, $thumbnails = NULL) { $attachment = get_post($attachment_id); $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); $sizes = ajax_thumbnail_rebuild_get_sizes(); $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes); foreach ($sizes as $size => $size_data) { if (isset($thumbnails) && !in_array($size, $thumbnails)) { $intermediate_size = image_get_intermediate_size($attachment_id, $size_data['name']); } else { $intermediate_size = image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']); } if ($intermediate_size) { $metadata['sizes'][$size] = $intermediate_size; } } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); }
function ed_delete_attachment($attach_id) { $meta = wp_get_attachment_metadata($attach_id); $sizes = $meta['sizes']; if (!sizes || !is_array($sizes)) { return $meta; } $uploads = wp_upload_dir(); $pi = pathinfo($meta['file']); $x2_filename = trailingslashit($uploads['basedir']) . $pi['dirname'] . '/' . $pi['filename'] . '@2x.' . $pi['extension']; if (file_exists($x2_filename) && file_is_displayable_image($x2_filename)) { unlink($x2_filename); } }
/** * Generate post thumbnail attachment meta data. * * @since 2.1.0 * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. * @return mixed Metadata for attachment. */ function wp_generate_attachment_metadata($attachment_id, $file) { $attachment = get_post($attachment_id); $metadata = array(); $support = false; if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); // make thumbnails and other intermediate sizes global $_wp_additional_image_sizes; $sizes = array(); foreach (get_intermediate_image_sizes() as $s) { $sizes[$s] = array('width' => '', 'height' => '', 'crop' => false); if (isset($_wp_additional_image_sizes[$s]['width'])) { $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']); } else { $sizes[$s]['width'] = get_option("{$s}_size_w"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['height'])) { $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']); } else { $sizes[$s]['height'] = get_option("{$s}_size_h"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['crop'])) { $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']); } else { $sizes[$s]['crop'] = get_option("{$s}_crop"); } // For default sizes set in options } $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes); if ($sizes) { $editor = wp_get_image_editor($file); if (!is_wp_error($editor)) { $metadata['sizes'] = $editor->multi_resize($sizes); } } else { $metadata['sizes'] = array(); } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } elseif (preg_match('#^video/#', get_post_mime_type($attachment))) { $metadata = wp_read_video_metadata($file); $support = current_theme_supports('post-thumbnails', 'attachment:video') && post_type_supports('attachment:video', 'thumbnail'); } elseif (preg_match('#^audio/#', get_post_mime_type($attachment))) { $metadata = wp_read_audio_metadata($file); $support = current_theme_supports('post-thumbnails', 'attachment:audio') && post_type_supports('attachment:audio', 'thumbnail'); } if ($support && !empty($metadata['image']['data'])) { $ext = '.jpg'; switch ($metadata['image']['mime']) { case 'image/gif': $ext = '.gif'; break; case 'image/png': $ext = '.png'; break; } $basename = str_replace('.', '-', basename($file)) . '-image' . $ext; $uploaded = wp_upload_bits($basename, '', $metadata['image']['data']); if (false === $uploaded['error']) { $attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => ''); $sub_attachment_id = wp_insert_attachment($attachment, $uploaded['file']); $attach_data = wp_generate_attachment_metadata($sub_attachment_id, $uploaded['file']); wp_update_attachment_metadata($sub_attachment_id, $attach_data); update_post_meta($attachment_id, '_thumbnail_id', $sub_attachment_id); } } // remove the blob of binary data from the array unset($metadata['image']['data']); return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); }
/** * Resize an image on demand * * @param int $attachment_id Attachment ID * @param string|array $size Size to be generated * * @return boolean Image generation result * * @since 2.3 */ function pods_image_resize($attachment_id, $size) { $size_data = array(); // Basic image size string if (!is_array($size)) { global $wp_image_sizes; // Registered image size if (isset($wp_image_sizes[$size]) && !empty($wp_image_sizes[$size])) { $size_data = $wp_image_sizes[$size]; } elseif (preg_match('/[0-9]+x[0-9]+/', $size) || preg_match('/[0-9]+x[0-9]+x[0-1]/', $size)) { $size = explode('x', $size); $size_data = array('width' => (int) $size[0], 'height' => (int) $size[1], 'crop' => (int) (isset($size[2]) ? $size[2] : 1)); $size = $size_data['width'] . 'x' . $size_data['height']; } } elseif (2 <= count($size)) { if (isset($size['width'])) { $size_data = $size; } else { $size_data = array('width' => (int) $size[0], 'height' => (int) $size[1], 'crop' => (int) (isset($size[2]) ? $size[2] : 1)); } $size = $size_data['width'] . 'x' . $size_data['height']; } if (empty($size_data)) { return false; } require_once ABSPATH . 'wp-admin/includes/image.php'; $attachment = get_post($attachment_id); $file = get_attached_file($attachment_id); if ($file && file_exists($file)) { $metadata = wp_get_attachment_metadata($attachment_id); if (!empty($metadata) && preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $editor = wp_get_image_editor($file); if (!is_wp_error($editor)) { $metadata['sizes'] = array_merge($metadata['sizes'], $editor->multi_resize(array($size => $size_data))); wp_update_attachment_metadata($attachment_id, $metadata); return true; } } } return false; }
/** * Generate gmedia meta data. * * @see wp_generate_attachment_metadata() * * @param int $media_id Gmedia Id to process. * @param array $fileinfo from fileinfo() function * * @return mixed Metadata for media. */ function generate_gmedia_metadata($media_id, $fileinfo = array()) { global $gmCore; $media = $this->get_gmedia($media_id); if (empty($fileinfo)) { $fileinfo = $gmCore->fileinfo($media->gmuid, false); } $metadata = array(); require_once ABSPATH . 'wp-admin/includes/image.php'; if (preg_match('!^image/!', $media->mime_type) && file_is_displayable_image($fileinfo['filepath'])) { $imagesize = getimagesize($fileinfo['filepath']); $metadata['web'] = array('width' => $imagesize[0], 'height' => $imagesize[1]); $imagesize = getimagesize($fileinfo['filepath_original']); $metadata['original'] = array('width' => $imagesize[0], 'height' => $imagesize[1]); $imagesize = getimagesize($fileinfo['filepath_thumb']); $metadata['thumb'] = array('width' => $imagesize[0], 'height' => $imagesize[1]); $metadata['file'] = $this->_gm_relative_upload_path($fileinfo['filepath']); // fetch additional metadata from exif/iptc $image_meta = $gmCore->wp_read_image_metadata($fileinfo['filepath_original']); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } elseif (preg_match('#^video/#', $media->mime_type)) { $metadata = $gmCore->wp_read_video_metadata($fileinfo['filepath']); } elseif (preg_match('#^audio/#', $media->mime_type)) { $metadata = $gmCore->wp_read_audio_metadata($fileinfo['filepath']); } return apply_filters('generate_gmedia_metadata', $metadata, $media_id); }
/** * Generate meta data for the media * * @since 1.0.0 * * @access private * @param int $attachment_id Media ID to process. * @param string $file Filepath of the Attached image. * * @return mixed Metadata for attachment. */ public function generate_metadata($attachment_id, $file) { $attachment = get_post($attachment_id); $mime_type = get_post_mime_type($attachment); $metadata = array(); if (preg_match('!^image/!', $mime_type) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); //get the registered media sizes $sizes = mpp_get_media_sizes(); $sizes = apply_filters('mpp_intermediate_image_sizes', $sizes, $attachment_id); if ($sizes) { $editor = wp_get_image_editor($file); if (!is_wp_error($editor)) { $metadata['sizes'] = $editor->multi_resize($sizes); } } else { $metadata['sizes'] = array(); } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } elseif (preg_match('#^video/#', $mime_type)) { $metadata = wp_read_video_metadata($file); } elseif (preg_match('#^audio/#', $mime_type)) { $metadata = wp_read_audio_metadata($file); } $dir_path = trailingslashit(dirname($file)) . 'covers'; $url = wp_get_attachment_url($attachment_id); $base_url = str_replace(wp_basename($url), '', $url); //processing for audio/video cover if (!empty($metadata['image']['data'])) { $ext = '.jpg'; switch ($metadata['image']['mime']) { case 'image/gif': $ext = '.gif'; break; case 'image/png': $ext = '.png'; break; } $basename = str_replace('.', '-', basename($file)) . '-image' . $ext; $uploaded = $this->upload_bits($basename, $metadata['image']['data'], array('path' => $dir_path, 'url' => $base_url)); if (false === $uploaded['error']) { $attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => ''); $sub_attachment_id = wp_insert_attachment($attachment, $uploaded['file']); $attach_data = $this->generate_metadata($sub_attachment_id, $uploaded['file']); wp_update_attachment_metadata($sub_attachment_id, $attach_data); //if the option is set to set post thumbnail if (mpp_get_option('set_post_thumbnail')) { mpp_update_media_meta($attachment_id, '_thumbnail_id', $sub_attachment_id); } //set the cover id mpp_update_media_cover_id($attachment_id, $sub_attachment_id); } } // remove the blob of binary data from the array if (isset($metadata['image']['data'])) { unset($metadata['image']['data']); } return apply_filters('mpp_generate_metadata', $metadata, $attachment_id); }
function gllr_wp_generate_attachment_metadata($attachment_id, $file, $metadata) { $attachment = get_post($attachment_id); $gllr_options = get_option('gllr_options'); add_image_size('album-thumb', $gllr_options['gllr_custom_size_px'][0][0], $gllr_options['gllr_custom_size_px'][0][1], true); add_image_size('photo-thumb', $gllr_options['gllr_custom_size_px'][1][0], $gllr_options['gllr_custom_size_px'][1][1], true); $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; /* Make the file path relative to the upload dir */ $metadata['file'] = _wp_relative_upload_path($file); /* Make thumbnails and other intermediate sizes */ global $_wp_additional_image_sizes; $image_size = array('album-thumb', 'photo-thumb', 'thumbnail'); /*get_intermediate_image_sizes();*/ foreach ($image_size as $s) { $sizes[$s] = array('width' => '', 'height' => '', 'crop' => FALSE); if (isset($_wp_additional_image_sizes[$s]['width'])) { $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']); } else { $sizes[$s]['width'] = get_option("{$s}_size_w"); } /* For default sizes set in options */ if (isset($_wp_additional_image_sizes[$s]['height'])) { $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']); } else { $sizes[$s]['height'] = get_option("{$s}_size_h"); } /* For default sizes set in options */ if (isset($_wp_additional_image_sizes[$s]['crop'])) { $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']); } else { $sizes[$s]['crop'] = get_option("{$s}_crop"); } /* For default sizes set in options */ } $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes); foreach ($sizes as $size => $size_data) { $resized = gllr_image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']); if ($resized) { $metadata['sizes'][$size] = $resized; } } /* Fetch additional metadata from exif/iptc */ $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); }
/** * Regenerate missing image dimensions for a particular attachment * @param (int) attachment ID * @return (array) new metadata for actual image **/ public function generate_thumb_missing($att_id) { // Fetch the attachment $att_raw = get_posts(array('include' => $att_id, 'post_type' => 'attachment', 'post_mime_type' => 'image')); $att = $att_raw[0]; $file = get_attached_file($att_id); // COMPLETE THIS SHIT. $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($att)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); // make thumbnails and other intermediate sizes global $_wp_additional_image_sizes; foreach (get_intermediate_image_sizes() as $s) { $sizes[$s] = array('width' => '', 'height' => '', 'crop' => FALSE); if (isset($_wp_additional_image_sizes[$s]['width'])) { $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']); } else { $sizes[$s]['width'] = get_option("{$s}_size_w"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['height'])) { $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']); } else { $sizes[$s]['height'] = get_option("{$s}_size_h"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['crop'])) { $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']); } else { $sizes[$s]['crop'] = get_option("{$s}_crop"); } // For default sizes set in options } $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes); // Only generate image if it does not already exist $att_meta = wp_get_attachment_metadata($att_id); foreach ($sizes as $size => $size_data) { // Size already exists if (isset($att_meta['sizes'][$size]) && file_exists($this->imageTrySize($file, $size_data['width'], $size_data['height']))) { $metadata['sizes'][$size] = $att_meta['sizes'][$size]; } else { // Generate new image $resized = image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']); if ($resized) { $metadata['sizes'][$size] = $resized; } } } // Get image meta and update database manually $metadata['image_meta'] = wp_read_image_metadata($file); update_post_meta($att_id, "_wp_attachment_metadata", $metadata); } return $att; }
function add_media_to_content($post_id, $file, $more_than_1 = false) { $post_fields = array('post_title', 'post_content', 'post_excerpt'); $image_file = file_is_displayable_image($file['new_file']); $html = $file['url']; if (isset($file['acf'])) { update_field($file['acf']['field_id'], $file['new_id'], $post_id); } elseif (in_array($file['field'], $post_fields)) { $tag = '#_gc_file_name_' . $file['counter'] . '#'; $post = get_post($post_id); if ($image_file) { $html = '<a href="' . $file['url'] . '"><img src="' . $file['url'] . '" alt="' . esc_attr($file['title']) . '" /></a>' . "\n"; } else { $html = '<a href="' . $file['url'] . '">' . $file['title'] . '</a>' . "\n"; } if ($more_than_1) { $html .= $tag; } $post = (array) $post; $new_post = array('ID' => $post_id, $file['field'] => str_replace($tag, $html, $post[$file['field']])); wp_update_post($new_post); } elseif ($file['field'] == 'gc_featured_image_') { update_post_meta($post_id, '_thumbnail_id', $file['new_id']); } else { add_post_meta($post_id, $file['field'], $html); } }
function handle_media_sideload($url, $parent_post_id = 0) { if (!function_exists('download_url') || !function_exists('media_handle_sideload')) { return false; } // if we didn't get a URL, let's bail $parsed = @parse_url($url); if (empty($parsed)) { return false; } $tmp = download_url($url); if (is_wp_error($tmp)) { return $tmp; } // First check to see if we get a mime-type match by file, otherwise, check to // see if WordPress supports this file as an image. If neither, then it is not supported. if (!$this->is_file_supported_for_sideloading($tmp) && !file_is_displayable_image($tmp)) { unlink($tmp); return false; } // emulate a $_FILES entry $file_array = array('name' => basename(parse_url($url, PHP_URL_PATH)), 'tmp_name' => $tmp); $id = media_handle_sideload($file_array, $parent_post_id); @unlink($tmp); if (is_wp_error($id)) { return $id; } if (!$id || !is_int($id)) { return false; } return $id; }
protected function processor() { global $user_ID, $gmCore, $gmDB, $gmGallery; if (!$gmCore->caps['gmedia_library']) { wp_die(__('You are not allowed to be here', 'grand-media')); } include_once GMEDIA_ABSPATH . 'admin/pages/library/functions.php'; if (in_array($this->mode, array('select_single', 'select_multiple'))) { $this->display_mode = 'grid'; } if (isset($_GET['display_mode'])) { $display_mode = $_GET['display_mode']; if (in_array($display_mode, array('grid', 'list'))) { $view = $this->gmediablank ? '_frame' : ''; $this->user_options = array_merge($this->user_options, array("display_mode_gmedia{$view}" => $display_mode)); update_user_meta($user_ID, 'gm_screen_options', $this->user_options); } $location = remove_query_arg('display_mode'); wp_redirect($location); exit; } if (isset($_GET['grid_cell_fit'])) { $this->user_options['grid_cell_fit_gmedia'] = !$this->user_options['grid_cell_fit_gmedia']; update_user_meta($user_ID, 'gm_screen_options', $this->user_options); if (isset($_GET['ajaxload'])) { exit; } $location = remove_query_arg('grid_cell_fit'); wp_redirect($location); exit; } if (isset($_GET['gallery'])) { $location = $this->url; $gallery_id = $gmCore->_get('gallery'); if ($gallery_id) { $gallery_query = $gmDB->get_metadata('gmedia_term', $gallery_id, '_query', true); $location = add_query_arg($gallery_query, $location); } wp_redirect($location); exit; } $this->query_args = $this->query_args(); if (isset($_POST['quick_gallery'])) { check_admin_referer('gmedia_action'); do { if (!$gmCore->caps['gmedia_gallery_manage']) { $this->error[] = __('You are not allowed to manage galleries', 'grand-media'); break; } $gallery = $gmCore->_post('gallery'); $gallery['name'] = trim($gallery['name']); if (empty($gallery['name'])) { $this->error[] = __('Gallery Name is not specified', 'grand-media'); break; } if ($gmCore->is_digit($gallery['name'])) { $this->error[] = __("Gallery name can't be only digits", 'grand-media'); break; } if (empty($gallery['query']['gmedia__in'])) { $this->error[] = __('Choose gmedia from library for quick gallery', 'grand-media'); break; } $taxonomy = 'gmedia_gallery'; if ($term_id = $gmDB->term_exists($gallery['name'], $taxonomy)) { $this->error[] = __('A term with the name provided already exists', 'grand-media'); break; } $term_id = $gmDB->insert_term($gallery['name'], $taxonomy); if (is_wp_error($term_id)) { $this->error[] = $term_id->get_error_message(); break; } $getModulePreset = $gmCore->getModulePreset($gallery['module']); $gallery['query'] = array_merge($gallery['query'], array('order' => 'ASC', 'orderby' => 'gmedia__in')); $gallery_meta = array('_edited' => gmdate('Y-m-d H:i:s'), '_query' => $gallery['query'], '_module' => $getModulePreset['module'], '_settings' => $getModulePreset['settings']); foreach ($gallery_meta as $key => $value) { $gmDB->update_metadata('gmedia_term', $term_id, $key, $value); } $this->msg[] = sprintf(__('Gallery "%s" successfuly saved. Shortcode: [gmedia id=%d]', 'grand-media'), esc_attr($gallery['name']), $term_id); } while (0); } if (isset($_POST['filter_categories'])) { if (false !== ($term = $gmCore->_post('cat'))) { $location = add_query_arg(array('category__in' => implode(',', $term)), $this->url); wp_redirect($location); exit; } } if (isset($_POST['filter_albums'])) { if (false !== ($term = $gmCore->_post('alb'))) { $location = add_query_arg(array('album__in' => implode(',', $term)), $this->url); wp_redirect($location); exit; } } if (isset($_POST['filter_tags'])) { if (false !== ($term = $gmCore->_post('tag_ids'))) { $location = add_query_arg(array('tag__in' => $term), $this->url); wp_redirect($location); exit; } } if (isset($_POST['filter_author'])) { $authors = $gmCore->_post('author_ids'); $location = add_query_arg(array('author' => (int) $authors), $this->url); wp_redirect($location); exit; } $do_gmedia = $gmCore->_get('do_gmedia'); if (!empty($this->selected_items) || isset($_POST['cookie_key'])) { if (isset($_POST['assign_album'])) { check_admin_referer('gmedia_action'); if ($gmCore->caps['gmedia_terms']) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $ids = $this->selected_items($cookie_key); if (!$gmCore->caps['gmedia_edit_others_media']) { $selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'gmedia__in' => $ids)); if (count($selected_items) < count($ids)) { $this->error[] = __('You are not allowed to edit others media', 'grand-media'); } } else { $selected_items = $ids; } $term = $gmCore->_post('alb'); if (false !== $term && ($count = count($selected_items))) { if (empty($term)) { foreach ($selected_items as $item) { $gmDB->delete_gmedia_term_relationships($item, 'gmedia_album'); } $this->msg[] = sprintf(__('%d item(s) updated with "No Album"', 'grand-media'), $count); } else { $term_ids = array(); foreach ($selected_items as $item) { $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_album', $append = 0); if (is_wp_error($result)) { $this->error[] = $result; } elseif ($result) { foreach ($result as $t_id) { $term_ids[$t_id][] = $item; } } } if (!empty($term_ids)) { global $wpdb; foreach ($term_ids as $term_id => $item_ids) { $term = $gmDB->get_term($term_id); if (isset($_POST['status_global'])) { $values = array(); foreach ($selected_items as $item) { $values[] = $wpdb->prepare("%d", $item); } if ($values) { $status = esc_sql($term->status); if (false === $wpdb->query("UPDATE {$wpdb->prefix}gmedia SET status = '{$status}' WHERE ID IN (" . join(',', $values) . ")")) { $this->error[] = __('Could not update statuses for gmedia items in the database'); } } } $this->msg[] = sprintf(__('Album `%s` assigned to %d item(s)', 'grand-media'), esc_html($term->name), count($item_ids)); } } } $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } } else { $this->error[] = __('You are not allowed to assign terms', 'grand-media'); } } if (isset($_POST['assign_category'])) { check_admin_referer('gmedia_action'); if ($gmCore->caps['gmedia_terms']) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $ids = $this->selected_items($cookie_key); if (!$gmCore->caps['gmedia_edit_others_media']) { $selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'gmedia__in' => $ids)); if (count($selected_items) < count($ids)) { $this->error[] = __('You are not allowed to edit others media', 'grand-media'); } } else { $selected_items = $ids; } $term = $gmCore->_post('cat_names'); $term = explode(',', $term); if (!empty($term) && ($count = count($selected_items))) { foreach ($selected_items as $item) { $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_category', $append = 1); if (is_wp_error($result)) { $this->error[] = $result; $count--; } elseif (!$result) { $count--; } } $this->msg[] = sprintf(__("Categories assigned to %d image(s).", 'grand-media'), $count); $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } } else { $this->error[] = __('You are not allowed to assign terms', 'grand-media'); } } if (isset($_POST['unassign_category'])) { check_admin_referer('gmedia_action'); if (($term = $gmCore->_post('category_id')) && $gmCore->caps['gmedia_terms']) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $ids = $this->selected_items($cookie_key); if (!$gmCore->caps['gmedia_edit_others_media']) { $selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'gmedia__in' => $ids)); if (count($selected_items) < count($ids)) { $this->error[] = __('You are not allowed to edit others media', 'grand-media'); } } else { $selected_items = $ids; } $term = array_map('intval', $term); if ($count = count($selected_items)) { foreach ($selected_items as $item) { $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_category', $append = -1); if (is_wp_error($result)) { $this->error[] = $result; $count--; } elseif (!$result) { $count--; } } $this->msg[] = sprintf(__('%d category(ies) deleted from %d item(s)', 'grand-media'), count($term), $count); $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } } else { $this->error[] = __('You are not allowed to assign terms', 'gmedia_grand-media'); } } if (isset($_POST['add_tags'])) { check_admin_referer('gmedia_action'); if (!$gmCore->caps['gmedia_terms']) { $this->error[] = __('You are not allowed to assign terms', 'grand-media'); } else { $term = $gmCore->_post('tag_names'); $iptc_tags = $gmCore->_post('iptc_tags'); if ($term || $iptc_tags) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $ids = $this->selected_items($cookie_key); if (!$gmCore->caps['gmedia_edit_others_media']) { $selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'gmedia__in' => $ids)); if (count($selected_items) < count($ids)) { $this->error[] = __('You are not allowed to edit others media', 'grand-media'); } } else { $selected_items = $ids; } $term = explode(',', $term); if ($count = count($selected_items)) { foreach ($selected_items as $item) { $_term = $term; if ($iptc_tags) { $_metadata = $gmDB->get_metadata('gmedia', $item, '_metadata', true); if (isset($_metadata['image_meta']['keywords']) && is_array($_metadata['image_meta']['keywords'])) { $_term = array_merge($_metadata['image_meta']['keywords'], $term); } } $result = $gmDB->set_gmedia_terms($item, $_term, 'gmedia_tag', $append = 1); if (is_wp_error($result)) { $this->error[] = $result; $count--; } elseif (!$result) { $count--; } } $this->msg[] = sprintf(__('Tags added to %d item(s)', 'grand-media'), $count); $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } } else { $this->error[] = __('No tags specified', 'grand-media'); } } } if (isset($_POST['delete_tags'])) { check_admin_referer('gmedia_action'); if (($term = $gmCore->_post('tag_id')) && $gmCore->caps['gmedia_terms']) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $ids = $this->selected_items($cookie_key); if (!$gmCore->caps['gmedia_edit_others_media']) { $selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'gmedia__in' => $ids)); if (count($selected_items) < count($ids)) { $this->error[] = __('You are not allowed to edit others media', 'grand-media'); } } else { $selected_items = $ids; } $term = array_map('intval', $term); if ($count = count($selected_items)) { foreach ($selected_items as $item) { $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_tag', $append = -1); if (is_wp_error($result)) { $this->error[] = $result; $count--; } elseif (!$result) { $count--; } } $this->msg[] = sprintf(__('%d tag(s) deleted from %d item(s)', 'grand-media'), count($term), $count); $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } } else { $this->error[] = __('You are not allowed to assign terms', 'grand-media'); } } if (isset($_POST['batch_edit'])) { check_admin_referer('gmedia_action'); if ($gmCore->caps['gmedia_edit_media']) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $ids = $this->selected_items($cookie_key); if (!$gmCore->caps['gmedia_edit_others_media']) { $selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'gmedia__in' => $ids)); if (count($selected_items) < count($ids)) { $this->error[] = __('You are not allowed to edit others media', 'grand-media'); } } else { $selected_items = $ids; } if ($count = count($selected_items)) { $batch_data = array(); $b_filename = $gmCore->_post('batch_filename'); $b_title = $gmCore->_post('batch_title'); $b_description = $gmCore->_post('batch_description'); $b_link = $gmCore->_post('batch_link'); $b_status = $gmCore->_post('batch_status'); $b_comment_status = $gmCore->_post('batch_comment_status'); if ($b_status) { $batch_data['status'] = $b_status; } if ($b_comment_status) { $batch_data['comment_status'] = $b_comment_status; } $b_author = $gmCore->_post('batch_author'); if ($b_author && '-1' != $b_author) { $batch_data['author'] = $b_author; } $i = 0; foreach ($selected_items as $item) { $id = (int) $item; $gmedia = $gmDB->get_gmedia($id, ARRAY_A); $item_author = (int) $gmedia['author']; if ('custom' == $b_filename && ($gmCore->caps['gmedia_delete_others_media'] || $item_author == $user_ID)) { $filename_custom = $gmCore->_post('batch_filename_custom'); if (!empty($filename_custom) && '{filename}' !== $filename_custom) { $gmuid = pathinfo($gmedia['gmuid']); $filename_vars = array('{filename}' => $gmuid['filename'], '{id}' => $gmedia['ID']); if (preg_match_all('/{index[:]?(\\d+)?}/', $filename_custom, $matches_all)) { foreach ($matches_all[0] as $key => $matches) { $strlen = strlen($matches_all[1][$key]); $index = intval($matches_all[1][$key]) + $i; $index = sprintf("%0{$strlen}d", $index); $filename_vars[$matches] = $index; } } $filename_custom = strtr($filename_custom, $filename_vars); $filename_custom = preg_replace('/[^a-z0-9_\\.-]+/i', '_', $filename_custom); if ($filename_custom && $filename_custom != $gmuid['filename']) { $fileinfo = $gmCore->fileinfo($filename_custom . '.' . $gmuid['extension']); if (false !== $fileinfo) { if ('image' == $fileinfo['dirname']) { /** WordPress Image Administration API */ require_once ABSPATH . 'wp-admin/includes/image.php'; if (file_is_displayable_image($fileinfo['dirpath'] . '/' . $gmedia['gmuid'])) { if (is_file($fileinfo['dirpath_original'] . '/' . $gmedia['gmuid'])) { @rename($fileinfo['dirpath_original'] . '/' . $gmedia['gmuid'], $fileinfo['filepath_original']); } @rename($fileinfo['dirpath_thumb'] . '/' . $gmedia['gmuid'], $fileinfo['filepath_thumb']); } } if (@rename($fileinfo['dirpath'] . '/' . $gmedia['gmuid'], $fileinfo['filepath'])) { $gmedia['gmuid'] = $fileinfo['basename']; $batch_data['gmuid'] = $fileinfo['basename']; } } } } } switch ($b_title) { case 'empty': $batch_data['title'] = ''; break; case 'filename': $title = pathinfo($gmedia['gmuid'], PATHINFO_FILENAME); $batch_data['title'] = str_replace('_', ' ', $title); if ($gmGallery->options['name2title_capitalize']) { $batch_data['title'] = mb_convert_case($batch_data['title'], MB_CASE_TITLE, 'UTF-8'); } break; case 'custom': $title_custom = $gmCore->_post('batch_title_custom'); if (false !== $title_custom) { $batch_data['title'] = $title_custom; } break; } switch ($b_description) { case 'empty': $batch_data['description'] = ''; break; case 'metadata': $metatext = $gmCore->metadata_text($id); if ($gmedia['description']) { $gmedia['description'] .= "\n"; } $batch_data['description'] = $gmedia['description'] . $metatext; break; case 'custom': $description_custom = $gmCore->_post('batch_description_custom'); if (false !== $description_custom) { $what_description_custom = $gmCore->_post('what_description_custom'); if ('replace' == $what_description_custom) { $batch_data['description'] = $description_custom; } elseif ('append' == $what_description_custom) { $batch_data['description'] = $gmedia['description'] . $description_custom; } elseif ('prepend' == $what_description_custom) { $batch_data['description'] = $description_custom . $gmedia['description']; } } break; } switch ($b_link) { case 'empty': $batch_data['link'] = ''; break; case 'self': $fileinfo = $gmCore->fileinfo($gmedia['gmuid'], false); $fileurl = is_file($fileinfo['filepath_original']) ? $fileinfo['fileurl_original'] : $fileinfo['fileurl']; $batch_data['link'] = $fileurl; break; case 'custom': $link_custom = $gmCore->_post('batch_link_custom'); if (false !== $link_custom) { $batch_data['link'] = $link_custom; } break; } if (!empty($batch_data)) { $batch_data['modified'] = current_time('mysql'); $gmedia_data = array_merge($gmedia, $batch_data); $gmDB->insert_gmedia($gmedia_data); } else { $count--; } $i++; } $this->msg[] = sprintf(__('%d item(s) updated successfuly', 'grand-media'), $count); $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } } else { $this->error[] = __('You are not allowed to edit media', 'grand-media'); } } if ($do_gmedia) { if ('unassign_album' == $do_gmedia) { check_admin_referer('gmedia_action'); if ($gmCore->caps['gmedia_terms']) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $ids = $this->selected_items($cookie_key); if (!$gmCore->caps['gmedia_edit_others_media']) { $selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'gmedia__in' => $ids)); if (count($selected_items) < count($ids)) { $this->error[] = __('You are not allowed to edit others media', 'grand-media'); } } else { $selected_items = $ids; } if ($count = count($selected_items)) { foreach ($selected_items as $item) { $gmDB->delete_gmedia_term_relationships($item, 'gmedia_album'); } $this->msg[] = sprintf(__('%d item(s) updated with "No Album"', 'grand-media'), $count); set_transient('gmedia_action_msg', $this->msg, 30); $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } } else { $this->error[] = __('You are not allowed to assign terms', 'grand-media'); set_transient('gmedia_action_error', $this->error, 30); } } if ('update_meta' == $do_gmedia) { check_admin_referer('gmedia_action'); if ($gmCore->caps['gmedia_edit_media']) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $selected_items = $this->selected_items($cookie_key); $count = count($selected_items); if ($count) { foreach ($selected_items as $item) { $id = (int) $item; $media_metadata = $gmDB->generate_gmedia_metadata($id); $gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $media_metadata); if (!empty($media_metadata['image_meta']['created_timestamp'])) { $gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_created_timestamp', $media_metadata['image_meta']['created_timestamp']); } if (!empty($media_metadata['image_meta']['GPS'])) { $gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_gps', $media_metadata['image_meta']['GPS']); } } $this->msg[] = sprintf(__('%d item(s) updated successfuly', 'grand-media'), $count); set_transient('gmedia_action_msg', $this->msg, 30); } $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } else { $this->error[] = __('You are not allowed to edit media', 'grand-media'); set_transient('gmedia_action_error', $this->error, 30); } } if ('recreate' == $do_gmedia) { check_admin_referer('gmedia_action'); if ($gmCore->caps['gmedia_edit_media']) { $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $selected_items = $this->selected_items($cookie_key); $count = count($selected_items); if ($count) { if (!$gmCore->caps['gmedia_edit_others_media']) { $edit_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'mime_type' => 'image', 'gmedia__in' => $selected_items)); $selected_items = $edit_items; } else { $selected_items = $gmDB->get_gmedias(array('fields' => 'ids', 'mime_type' => 'image', 'gmedia__in' => $selected_items)); } if ($count = count($selected_items)) { $ajax_operations = get_option('gmedia_ajax_long_operations', array()); foreach ($selected_items as $si) { $ajax_operations['gmedia_recreate_images'][$si] = $si; } update_option('gmedia_ajax_long_operations', $ajax_operations); $this->msg[] = sprintf(__('You\'ve added %d image(s) to the re-creation queue.', 'grand-media'), $count); set_transient('gmedia_action_msg', $this->msg, 30); } } $this->clear_selected_items($cookie_key); $this->selected_items = $this->selected_items(self::$cookie_key); } else { $this->error[] = __('You are not allowed to edit media', 'grand-media'); set_transient('gmedia_action_error', $this->error, 30); } } } } if ('duplicate' == $do_gmedia) { check_admin_referer('gmedia_action'); if ($gmCore->caps['gmedia_upload'] || $gmCore->caps['gmedia_import']) { $ids = $gmCore->_get('ids', 'selected'); $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $selected_items = 'selected' == $ids ? $this->selected_items($cookie_key) : wp_parse_id_list($ids); if (!empty($selected_items)) { if ($count = count($selected_items)) { foreach ($selected_items as $gmid) { $gmCore->duplicate_gmedia($gmid); } $this->msg[] = sprintf(__('%d item duplicated (without terms)', 'grand-media'), $count); set_transient('gmedia_action_msg', $this->msg, 30); } } } else { $this->error[] = __('You are not allowed to import files', 'grand-media'); set_transient('gmedia_action_error', $this->error, 30); } } if ('delete' == $do_gmedia || 'delete__save_original' == $do_gmedia) { check_admin_referer('gmedia_delete'); if ($gmCore->caps['gmedia_delete_media']) { $ids = $gmCore->_get('ids', 'selected'); $cookie_key = $gmCore->_post('cookie_key', self::$cookie_key); $selected_items = 'selected' == $ids ? $this->selected_items($cookie_key) : wp_parse_id_list($ids); if (!empty($selected_items)) { if (!$gmCore->caps['gmedia_delete_others_media']) { $delete_items = $gmDB->get_gmedias(array('fields' => 'ids', 'author' => $user_ID, 'gmedia__in' => $selected_items)); if (count($delete_items) < count($selected_items)) { $this->error[] = __('You are not allowed to delete others media', 'grand-media'); } $selected_items = $delete_items; } if ($count = count($selected_items)) { $delete_original_file = !('delete__save_original' == $do_gmedia); foreach ($selected_items as $item) { if (!$gmDB->delete_gmedia((int) $item, $delete_original_file)) { $this->error[] = "#{$item}: " . __('Error in deleting...', 'grand-media'); $count--; } } if ($count) { if ($delete_original_file) { $this->msg[] = sprintf(__('%d item(s) deleted successfuly', 'grand-media'), $count); } else { $this->msg[] = sprintf(__('%d record(s) deleted from database successfuly. Original file(s) safe', 'grand-media'), $count); } } $this->selected_items = array_diff($this->selected_items, $selected_items); if (empty($this->selected_items)) { $this->clear_selected_items(self::$cookie_key); } else { setcookie(self::$cookie_key, implode('.', $this->selected_items)); } if ($cookie_key != self::$cookie_key) { if ('selected' == $ids) { $this->clear_selected_items($cookie_key); } else { $_selected_items = $this->selected_items($cookie_key); $_selected_items = array_diff($_selected_items, $selected_items); if (empty($_selected_items)) { $this->clear_selected_items($cookie_key); } else { setcookie($cookie_key, implode('.', $_selected_items)); } } } if (!empty($this->stack_items)) { $this->stack_items = array_diff($this->stack_items, $selected_items); if (empty($this->stack_items)) { $this->clear_selected_items("gmedia_{$user_ID}_libstack"); } else { setcookie("gmedia_{$user_ID}_libstack", implode('.', $this->stack_items)); } } } } } else { $this->error[] = __('You are not allowed to delete files', 'grand-media'); } if (!empty($this->msg)) { set_transient('gmedia_action_msg', $this->msg, 30); } if (!empty($this->error)) { set_transient('gmedia_action_error', $this->error, 30); } } if ($do_gmedia) { $location = remove_query_arg(array('do_gmedia', 'ids', '_wpnonce')); $location = add_query_arg('did_gmedia', $do_gmedia, $location); wp_redirect($location); exit; } if ($gmCore->_get('did_gmedia')) { $msg = get_transient('gmedia_action_msg'); if ($msg) { delete_transient('gmedia_action_msg'); $this->msg = (array) $msg; } $error = get_transient('gmedia_action_error'); if ($error) { delete_transient('gmedia_action_error'); $this->error = (array) $error; } } }
/** * Generate post thumbnail attachment meta data. * * @since 2.1.0 * * @global array $_wp_additional_image_sizes * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. * @return mixed Metadata for attachment. */ function wp_generate_attachment_metadata($attachment_id, $file) { $attachment = get_post($attachment_id); $metadata = array(); $support = false; if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; // Make the file path relative to the upload dir. $metadata['file'] = _wp_relative_upload_path($file); // Make thumbnails and other intermediate sizes. global $_wp_additional_image_sizes; $sizes = array(); foreach (get_intermediate_image_sizes() as $s) { $sizes[$s] = array('width' => '', 'height' => '', 'crop' => false); if (isset($_wp_additional_image_sizes[$s]['width'])) { $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']); } else { $sizes[$s]['width'] = get_option("{$s}_size_w"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['height'])) { $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']); } else { $sizes[$s]['height'] = get_option("{$s}_size_h"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['crop'])) { $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop']; } else { $sizes[$s]['crop'] = get_option("{$s}_crop"); } // For default sizes set in options } /** * Filter the image sizes automatically generated when uploading an image. * * @since 2.9.0 * @since 4.4.0 Added the `$metadata` argument. * * @param array $sizes An associative array of image sizes. * @param array $metadata An associative array of image metadata: width, height, file. */ $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes, $metadata); if ($sizes) { $editor = wp_get_image_editor($file); if (!is_wp_error($editor)) { $metadata['sizes'] = $editor->multi_resize($sizes); } } else { $metadata['sizes'] = array(); } // Fetch additional metadata from EXIF/IPTC. $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } elseif (wp_attachment_is('video', $attachment)) { $metadata = wp_read_video_metadata($file); $support = current_theme_supports('post-thumbnails', 'attachment:video') || post_type_supports('attachment:video', 'thumbnail'); } elseif (wp_attachment_is('audio', $attachment)) { $metadata = wp_read_audio_metadata($file); $support = current_theme_supports('post-thumbnails', 'attachment:audio') || post_type_supports('attachment:audio', 'thumbnail'); } if ($support && !empty($metadata['image']['data'])) { // Check for existing cover. $hash = md5($metadata['image']['data']); $posts = get_posts(array('fields' => 'ids', 'post_type' => 'attachment', 'post_mime_type' => $metadata['image']['mime'], 'post_status' => 'inherit', 'posts_per_page' => 1, 'meta_key' => '_cover_hash', 'meta_value' => $hash)); $exists = reset($posts); if (!empty($exists)) { update_post_meta($attachment_id, '_thumbnail_id', $exists); } else { $ext = '.jpg'; switch ($metadata['image']['mime']) { case 'image/gif': $ext = '.gif'; break; case 'image/png': $ext = '.png'; break; } $basename = str_replace('.', '-', basename($file)) . '-image' . $ext; $uploaded = wp_upload_bits($basename, '', $metadata['image']['data']); if (false === $uploaded['error']) { $image_attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => ''); /** * Filter the parameters for the attachment thumbnail creation. * * @since 3.9.0 * * @param array $image_attachment An array of parameters to create the thumbnail. * @param array $metadata Current attachment metadata. * @param array $uploaded An array containing the thumbnail path and url. */ $image_attachment = apply_filters('attachment_thumbnail_args', $image_attachment, $metadata, $uploaded); $sub_attachment_id = wp_insert_attachment($image_attachment, $uploaded['file']); add_post_meta($sub_attachment_id, '_cover_hash', $hash); $attach_data = wp_generate_attachment_metadata($sub_attachment_id, $uploaded['file']); wp_update_attachment_metadata($sub_attachment_id, $attach_data); update_post_meta($attachment_id, '_thumbnail_id', $sub_attachment_id); } } } // Remove the blob of binary data from the array. if ($metadata) { unset($metadata['image']['data']); } /** * Filter the generated attachment meta data. * * @since 2.1.0 * * @param array $metadata An array of attachment meta data. * @param int $attachment_id Current attachment ID. */ return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); }
function op_upload_file($name) { $uploads = wp_upload_dir(); $fileobj = is_array($name) ? $name : $_FILES[$name]; if (!empty($fileobj['tmp_name']) && file_is_displayable_image($fileobj['tmp_name'])) { if ($file = wp_handle_upload($fileobj, array('test_form' => false, 'action' => 'wp_handle_upload'))) { $sizes = array(); if (isset($field['field_opts'])) { $opts = $field['field_opts']; if (isset($opts['max_w']) && isset($opts['max_h'])) { $sizes = array($opts['max_w'], $opts['max_h']); } } $image_url = $file['url']; if (count($sizes) == 2) { $resized = image_make_intermediate_size($file['file'], $sizes[0], $sizes[1]); if ($resized) { $image_url = $uploads['url'] . '/' . $resized['file']; } } $attachment = array('post_title' => $fileobj['name'], 'post_content' => '', 'post_status' => 'inherit', 'post_mime_type' => $file['type'], 'guid' => $image_url); $aid = wp_insert_attachment($attachment, $file['file'], 0); if (!is_wp_error($aid)) { wp_update_attachment_metadata($aid, wp_generate_attachment_metadata($aid, $file['file'])); return array('image' => $image_url); } else { return array('error' => $aid->get_error_message()); } } } else { return array('error' => $fileobj['error'] == 4 ? false : __('The file you tried to upload is not a valid image.', OP_SN)); } }
function handle_media_sideload($url, $parent_post_id = 0) { if (!function_exists('download_url') || !function_exists('media_handle_sideload')) { return false; } // if we didn't get a URL, let's bail $parsed = @parse_url($url); if (empty($parsed)) { return false; } $tmp = download_url($url); if (is_wp_error($tmp)) { return false; } if (!file_is_displayable_image($tmp)) { @unlink($tmp); return false; } // emulate a $_FILES entry $file_array = array('name' => basename(parse_url($url, PHP_URL_PATH)), 'tmp_name' => $tmp); $id = media_handle_sideload($file_array, $parent_post_id); @unlink($tmp); if (!$id || !is_int($id)) { return false; } return $id; }
function gmedia_update_data() { global $gmDB, $gmCore; check_ajax_referer("GmediaGallery"); if (!current_user_can('gmedia_edit_media')) { die('-1'); } $data = $gmCore->_post('data'); wp_parse_str($data, $gmedia); if (!empty($gmedia['ID'])) { $item = $gmDB->get_gmedia($gmedia['ID']); if ((int) $item->author != get_current_user_id()) { if (!current_user_can('gmedia_edit_others_media')) { die('-2'); } } $gmedia['modified'] = current_time('mysql'); $gmedia['mime_type'] = $item->mime_type; $gmedia['gmuid'] = $item->gmuid; if (!current_user_can('gmedia_delete_others_media')) { $gmedia['author'] = $item->author; } $gmuid = pathinfo($item->gmuid); $gmedia['filename'] = preg_replace('/[^a-z0-9_\\.-]+/i', '_', $gmedia['filename']); if ($gmedia['filename'] != $gmuid['filename'] && (current_user_can('gmedia_delete_others_media') || (int) $item->author == get_current_user_id())) { $fileinfo = $gmCore->fileinfo($gmedia['filename'] . '.' . $gmuid['extension']); if (false !== $fileinfo) { if ('image' == $fileinfo['dirname'] && file_is_displayable_image($fileinfo['dirpath'] . '/' . $item->gmuid)) { if (is_file($fileinfo['dirpath_original'] . '/' . $item->gmuid)) { @rename($fileinfo['dirpath_original'] . '/' . $item->gmuid, $fileinfo['filepath_original']); } @rename($fileinfo['dirpath_thumb'] . '/' . $item->gmuid, $fileinfo['filepath_thumb']); } if (@rename($fileinfo['dirpath'] . '/' . $item->gmuid, $fileinfo['filepath'])) { $gmedia['gmuid'] = $fileinfo['basename']; } } } if (!current_user_can('gmedia_terms')) { unset($gmedia['terms']); } $id = $gmDB->insert_gmedia($gmedia); if (!is_wp_error($id)) { // Meta Stuff if (isset($gmedia['meta']) && is_array($gmedia['meta'])) { $meta_error = array(); foreach ($gmedia['meta'] as $key => $value) { if ($gmCore->is_digit($key)) { $mid = (int) $key; //$value = wp_unslash( $value ); if (!($meta = $gmDB->get_metadata_by_mid('gmedia', $mid))) { $meta_error[] = array('error' => 'no_meta', 'message' => __('No record in DataBase.', 'grand-media'), 'meta_id' => $mid, 'meta_key' => $meta->meta_key); continue; } if ('' == trim($value)) { $meta_error[] = array('error' => 'empty_value', 'message' => __('Please provide a custom field value.', 'grand-media'), 'meta_id' => $mid, 'meta_key' => $meta->meta_key, 'meta_value' => $meta->meta_value); continue; } if ($meta->meta_value != $value) { if (!($u = $gmDB->update_metadata_by_mid('gmedia', $mid, $value))) { $meta_error[] = array('error' => 'meta_update', 'message' => __('Something goes wrong.', 'grand-media'), 'meta_id' => $mid, 'meta_key' => $meta->meta_key, 'meta_value' => $meta->meta_value); } } } elseif ('_' == $key[0]) { if ('_cover' == $key) { $value = ltrim($value, '#'); } elseif ('_gps' == $key) { if ($value) { $latlng = explode(',', $value); $value = array('lat' => trim($latlng[0]), 'lng' => trim($latlng[1])); } } $value = apply_filters('gmedia_protected_meta_value', $value, $key, $id); $gmDB->update_metadata('gmedia', $id, $key, $value); } } } $result = $gmDB->get_gmedia($id); } else { $result = $gmDB->get_gmedia($id); } gmedia_item_more_data($result); if ('image' != $result->type) { $result->thumbnail = gmedia_item_thumbnail($result); } if (current_user_can('gmedia_terms')) { if (!empty($gmedia['terms']['gmedia_album'])) { if (isset($gmedia['gmedia_album_order'])) { $album = $gmDB->get_the_gmedia_terms($id, 'gmedia_album'); if ($album) { $album = reset($album); if ((int) $gmedia['gmedia_album_order'] != (int) $album->gmedia_order) { $gmDB->update_term_sortorder($album->term_id, array($id => (int) $gmedia['gmedia_album_order'])); $result->gmedia_album_order = (int) $gmedia['gmedia_album_order']; } } } $alb_id = $gmedia['terms']['gmedia_album']; $alb = $gmDB->get_term($alb_id, 'gmedia_album'); $result->album_status = $alb ? $alb->status : 'none'; } else { $result->album_status = 'none'; } } if (!empty($meta_error)) { $result->meta_error = $meta_error; } header('Content-Type: application/json; charset=' . get_option('blog_charset'), true); echo json_encode($result); } die; }
function handle_image_upload($upload) { global $post; if (file_is_displayable_image($upload['tmp_name'])) { //Check if image //handle the uploaded file $overrides = array('test_form' => false); $file = wp_handle_upload($upload, $overrides); } return $file; }
/** * Generate post image attachment meta data. * * @since 2.1.0 * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. * @return mixed Metadata for attachment. */ function wp_generate_attachment_metadata($attachment_id, $file) { $attachment = get_post($attachment_id); $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $full_path_file = $file; $imagesize = getimagesize($full_path_file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; // Make the file path relative to the upload dir if (($uploads = wp_upload_dir()) && false === $uploads['error']) { // Get upload directory if (0 === strpos($file, $uploads['basedir'])) { // Check that the upload base exists in the file path $file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path $file = ltrim($file, '/'); } } $metadata['file'] = $file; // make thumbnails and other intermediate sizes $sizes = array('thumbnail', 'medium', 'large'); $sizes = apply_filters('intermediate_image_sizes', $sizes); foreach ($sizes as $size) { $resized = image_make_intermediate_size($full_path_file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop")); if ($resized) { $metadata['sizes'][$size] = $resized; } } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($full_path_file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); }
/** * Generate post thumbnail attachment meta data. * * @since 2.1.0 * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. * * @param null|array $thumbnails: thumbnails to regenerate, if null all * * @return mixed Metadata for attachment. */ public static function wp_generate_attachment_metadata_custom($attachment_id, $file, $thumbnails = null) { $attachment = get_post($attachment_id); $meta_datas = get_post_meta($attachment_id, '_wp_attachment_metadata', true); $metadata = array(); if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) { $imagesize = getimagesize($file); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); $metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); // make thumbnails and other intermediate sizes global $_wp_additional_image_sizes; foreach (get_intermediate_image_sizes() as $s) { $sizes[$s] = array('width' => '', 'height' => '', 'crop' => false); if (isset($_wp_additional_image_sizes[$s]['width'])) { $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']); } else { $sizes[$s]['width'] = get_option("{$s}_size_w"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['height'])) { $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']); } else { $sizes[$s]['height'] = get_option("{$s}_size_h"); } // For default sizes set in options if (isset($_wp_additional_image_sizes[$s]['crop'])) { $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']); } else { $sizes[$s]['crop'] = get_option("{$s}_crop"); } // For default sizes set in options } $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes); // Only if not all sizes if (isset($thumbnails) && is_array($thumbnails) && isset($meta_datas['sizes']) && !empty($meta_datas['sizes'])) { // Fill the array with the other sizes not have to be done foreach ($meta_datas['sizes'] as $name => $fsize) { $metadata['sizes'][$name] = $fsize; } } foreach ($sizes as $size => $size_data) { if (isset($thumbnails)) { if (!in_array($size, $thumbnails)) { continue; } } $resized = image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']); if (isset($meta_datas['size'][$size])) { // Remove the size from the orignal sizes for after work unset($meta_datas['size'][$size]); } if ($resized) { $metadata['sizes'][$size] = $resized; } } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata($file); if ($image_meta) { $metadata['image_meta'] = $image_meta; } } return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id); }
function test_is_displayable_image_negative() { // these are image files but aren't suitable for web pages because of compatibility or size issues $files = array( // 'test-image-cmyk.jpg', Allowed in r9727 // 'test-image.bmp', Allowed in r28589 // 'test-image-grayscale.jpg', Allowed in r9727 'test-image.pct', 'test-image.tga', 'test-image.sgi', 'test-image.tiff', 'test-image-lzw.tiff', 'test-image.jp2', 'test-image.psd', 'test-image-zip.tiff', ); foreach ($files as $file) { $this->assertFalse( file_is_displayable_image( DIR_TESTDATA.'/images/'.$file ), "file_is_valid_image($file) should return false" ); } }