所以我有一个表格来上传GIF图像,我想保留动画GIF图像并转换/创建一个新的静态图像从GIF(获得第一帧)到JPG。
这是我的表格:
<form action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">
<fieldset>
<p>Upload funny pictures, paste pictures or YouTube URL, accepting GIF/JPG/PNG (Max size: 3MB)</p>
<label for="postTitle"><?php _e('* Title of the image:', 'framework') ?></label>
<input type="text" name="postTitle" id="postTitle" class="required" value="<?php if ( isset( $_POST['postTitle'] ) ) echo $_POST['postTitle']; ?>" />
</fieldset>
<div id="file-input" class="file-field">
<input type="file" name="thumbnail" id="thumbnail">
</div>
这是我的验证码:
// validation
wp_register_script( 'validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js', array( 'jquery' ) );
wp_enqueue_script( 'validation' );
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
if ( trim( $_POST['postTitle'] ) === '' ) {
$postTitleError = 'Please enter a title.';
$hasError = true;
}
$post_information = array(
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_content' => $_POST['postContent'],
'post_type' => 'post',
'post_status' => 'pending'
);
$new_post = wp_insert_post( $post_information );
if (!function_exists('wp_generate_attachment_metadata')){
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload( $file, $new_post );
}
}
if ($attach_id > 0){
//and if you want to set that image as Post then use:
update_post_meta($new_post,'_thumbnail_id',$attach_id);
}
}
我怎样才能做到这一点?