$value) {
$size_names[$key] = $key;
}
foreach ( $size_names as $size => $name ) {
$downsize = image_downsize($post->ID, $size);
// is this size selectable?
$enabled = ( $downsize[3] || 'full' == $size );
$css_id = "image-size-{$size}-{$post->ID}";
// if this size is the default but that's not available, don't select it
if ( $checked && !$enabled )
$checked = '';
// if $checked was not specified, default to the first available size that's bigger than a thumbnail
if ( !$checked && $enabled && 'thumbnail' != $size )
$checked = $size;
$html = "
ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />";
$html .= "" . __($name). " ";
// only show the dimensions if that choice is available
if ( $enabled )
$html .= " " . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). " ";
$html .= '
';
$out .= $html;
}
$form_fields['image-size']['html'] .= $out;
return $form_fields;
}
function ais_display_admin() {
$messages = ais_handle_post();
?>
Additional image sizes
Regenerate intermediate size images
Creating an additional image size means that for any new image you upload, a copy of this additional size will be created. If you'd like, this plugin can also create such a copy for any existing images. Click the button below to do this:
$delete was deleted";
}
update_option('ais_sizes', $ais_sizes);
$ais_sizes = get_option('ais_sizes');
}
if (empty($messages['errors'])) {
$ais_sizes[$_POST['ais_size_name']] = array(
'size_w' => $_POST['ais_size_w'],
'size_h' => $_POST['ais_size_h'],
'crop' => $_POST['ais_size_crop']
);
update_option('ais_sizes', $ais_sizes);
$messages['succes'][] = 'An additional image size named ' . $_POST['ais_size_name'] . ' was added.';
return $messages;
} elseif (isset($messages['errors']['width']) && isset($messages['errors']['height']) && isset($messages['errors']['size_name']) && !isset($_POST['ais_size_delete'])) {
// wanneer er geen nieuwe size is en geen delete wordt gedaan
unset($messages['errors']);
$messages['errors'][] = 'You just pressed Save changes without entering anything huh? Why?';
return $messages;
} elseif (isset($messages['errors']['width']) && isset($messages['errors']['height']) && isset($messages['errors']['size_name']) && isset($_POST['ais_size_delete'])) {
unset($messages['errors']);
return $messages;
} else return $messages;
}
function ais_regenerate_images() {
$messages = array();
$images = ais_get_images();
$sizes = apply_filters('intermediate_image_sizes', array('thumbnail', 'medium', 'large'));
$basedir = wp_upload_dir();
$basedir = $basedir['basedir'];
$i = 0;
foreach ($images as $image) {
if ($i > 10) continue;
$metadata = wp_get_attachment_metadata($image->ID);
foreach ($sizes as $size) {
if (!isset($metadata['sizes'][$size])) {
$image_path = $basedir . '/' . $metadata['file'];
$result = image_make_intermediate_size(
$image_path, get_option("{$size}_size_w"),
get_option("{$size}_size_h"),
get_option("{$size}_crop")
);
if ($result) {
$metadata['sizes'][$size] = array(
'file' => $result['file'], 'width' => $result['width'], 'height' => $result['height']
);
wp_update_attachment_metadata($image->ID, $metadata);
$messages['succes'][] = 'Resized ' . $image->post_title . ' to size ' . $size . '.';
$i++;
}
else {
$result = image_resize(
$image_path, get_option("{$size}_size_w"),
get_option("{$size}_size_h"),
get_option("{$size}_crop")
);
foreach ($errors as $key => $value) {
$messages['errors'][] = $key . ': ' . $value;
}
}
}
else {
$messages['succes'][] = $size . ' already exists for ' . $image->post_title . '. Skipped.';
}
}
}
return $messages;
}
function ais_get_images() {
/* Get attachments */
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'post_status' => null,
'post_parent' => null, // any parent
);
$attachments = get_posts($args);
if (empty($attachments)) return false;
else return $attachments;
}
function register_ais_settings() {
register_setting('ais_options', 'ais_sizes');
}
function ais_add_image_sizes($sizes) {
$ais_sizes = get_option('ais_sizes');
if (!empty($ais_sizes)) {
foreach ($ais_sizes as $key => $value) {
$sizes[] = $key;
update_option("{$key}_size_w", $value['size_w']);
update_option("{$key}_size_h", $value['size_h']);
update_option("{$key}_crop", $value['crop']);
}
}
return $sizes;
}
?>