/** * Generate a placeholder at a given size. * * @param int $id Attachment ID. * @param string $size Image size. * @param int $radius Blur radius. * @return array|null 3-tuple of binary image data (string), width (int), height (int) on success; null on error. */ function generate_placeholder($id, $size, $radius) { $size_data = get_size_data($size); if ($size !== 'full' && empty($size_data)) { _doing_it_wrong(__FUNCTION__, __('Invalid image size enabled for placeholders', 'gaussholder')); return null; } $img = wp_get_attachment_image_src($id, $size); $uploads = wp_upload_dir(); $path = str_replace($uploads['baseurl'], $uploads['basedir'], $img[0]); return JPEG\data_for_file($path, $radius); }
/** * Check how big the placeholder will be for an image or file with a given * radius. * * @subcommand check-size * @synopsis <id_or_file> <radius> * @param array $args */ public function check_size($args) { if (is_numeric($args[0])) { $attachment_id = absint($args[0]); $file = get_attached_file($attachment_id); if (empty($file)) { WP_CLI::error(__('Attachment does not exist', 'gaussholder')); } } else { $file = $args[1]; } if (!file_exists($file)) { WP_CLI::error(sprintf(__('File %s does not exist', 'gaussholder'), $file)); } // Generate a placeholder with the radius $radius = absint($args[1]); $data = JPEG\data_for_file($file, $radius); WP_CLI::line(sprintf('%s: %dB (%dpx radius)', basename($file), strlen($data[0]), $radius)); }