Support » Plugins and Hacks » Hacks » Get and resize Thumbnails with images taken from custom fields

  • Resolved refulez

    (@refulez)


    Hi,
    i need to generate thumbnails for a image taken from a custom field.
    how do i do that?
    i need to set thumbnail sizes like this
    “set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, resize mode”
    but for a image taken from a custom field of a post.

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • i would just upload it and then paste the url of the thumbnail into the custom field…

    i have a script that inserts the link of the image into the custom field. but what i need is: the wordpress thumbnail generator to use that image and generate thumbs of other sizes.

    so i don;t have to use resizing scripts like timthumb.

    so how do i get the wordpress thumbnail generator to use the image in a custom field?

    are you uploading the image to your wordpress install?

    i’m uploading them to a folder on the server and the i have a script that parses the folder and inserts into the database the link to the image.

    so any idea how to use a custom field for the thumbnail generation?

    check out the link below, it has what you are looking for and specifically wp_insert_attachment() is the function you need.

    http://wordpress.stackexchange.com/questions/4307/how-can-i-add-an-image-upload-field-directly-to-a-custom-write-panel/4413#4413

    thanks!

    here is the script in case someone else is looking for something like this

    $value is the filename
    
    $save_path = "folder/";
    $file = realpath($save_path).'/'.$value;
    $wp_filetype = wp_check_filetype(basename($file), null );
    
        // Construct the attachment array
        $attachment = array(
        'post_mime_type' => $wp_filetype['type'],
        'guid' => $file,
        'post_title' => preg_replace('/\.[^.]+$/', '', basename($post_name)),
        'post_content' => '',
        'post_parent' => $post_id,
    'post_status' => 'inherit'
        );
    
        // Save the data
        $id = wp_insert_attachment($attachment, $file, $post_id);
     $attach_data = wp_generate_attachment_metadata( $id, $file );
      wp_update_attachment_metadata( $id, $attach_data );
    set_post_thumbnail( $post_id, $id );
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Get and resize Thumbnails with images taken from custom fields’ is closed to new replies.