I’m using Wordpres 6.6.1
When we upload images through Media Library it’s created many scaled version of the image.
I have a plugin where I upload the image by own code. Here the code:
$hashed_filename = md5( $_FILES['images']['name'][$key] . microtime() ) . '_' . $_FILES['images']['name'][$key];
move_uploaded_file( $_FILES["images"]["tmp_name"][$key], $upload_dir['path']."/" . $hashed_filename);
$attachment = array(
'post_mime_type' => $_FILES['images']['type'][$key],
'post_title' => preg_replace('/.[^.]+$/', '', basename($hashed_filename)),
'post_content' => '',
'post_status' => 'inherit',
'guid' => $wp_upload_dir['url'] . '/' . basename($hashed_filename)
);
$attach_id = wp_insert_attachment( $attachment, $upload_dir['path'] . '/' . $hashed_filename );
$info = getimagesize($_FILES['images']['name'][$key]);
$meta = array (
'width' => $info[0],
'height' => $info[1],
'hwstring_small' => "height='{$info[1]}' width='{$info[0]}'",
'file' => preg_replace('/.[^.]+$/', '', basename($hashed_filename)),
'sizes' => array(),
'image_meta' => array(),
);
update_post_meta($attach_id, '_wp_attachment_metadata', $meta);
Problem is it upload only a version with original size of the image of course. I want to create multiple scaled version as Media Library. How can I do it?
Thanks
create scaled image when upload it.
dung nguyen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.