WordPress.org

Forums

Using getimagesize in wordpress... (6 posts)

  1. bluefrog1974
    Member
    Posted 2 years ago #

    I'm looking for a bit of help using getimagesize in wordpress. Before I continue though, if anybody knows of a different way to achieve the same result (image size and file size in posts) please let me know, I'm not bothered how it works so long as it does lol

    Currently I have:

    <?php
    $blah = getimagesize("myimagefile.jpg");
    $type = $blah['mime'];
    $width = $blah[0];
    $height = $blah[1];
    
    echo $blah[0];
    echo ' x ';
    echo $height;
    ?>

    which will output the files dimensions, however, I am having trouble finding a way to make the file dynamically placed in the image location. This is even more of a problem when the above code will only work with a server path home/xxx/xxx/xxx/etc

    Ok here is what I am trying to do:

    1. Take the largest (full size) image and dynamically place the information into the above code

    2. Convert the file location into a path, this could be achieved by using a static path upto a certain point, then stripping the code prior to the code strip.

    like http://mysite.com/wordpress/uploads/folder/image.jpg everything before the folder name such as uploads, be stripped and placed into the remaining path such as home/xxx/xxx/wordpress/uploads/ stripped code here.

    Any help? Any idea's? I must admit I'm stuck here and now. I don;t know much code so this might be really simple, I just don't know.

    Anyway, thanks in advance :)

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

  3. bluefrog1974
    Member
    Posted 2 years ago #

    Thanks, but I don't think this is going to be any easier than the php code as I would now have to dynamically find the attachment ID from the post and include it in the output. No idea on how to even begin doing that lol.

    Please correct me if I am misunderstanding the useage of it.

    Darren :)

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Are you using this code inside the Loop? If so, $post->ID will give you the post id.

  5. bluefrog1974
    Member
    Posted 2 years ago #

    Yeah thats what I'd normally do but the codex page stated that it works on the upload ID not the post ID, the post ID for a particular post is 1109 but the upload ID is 1034.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You could get the ids of all of the images attached to the post using get_posts.

Topic Closed

This topic has been closed to new replies.

About this Topic