Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm displaying a group of thumbnails on a Wordpress site using the Magic Fields plugin

Here's the code in my template:

  <?php
  $client_images = get_group ('images');
  foreach($client_images as $image){ ?>
  <div class="thumb">
      <a href="<?php echo $image['client_image'][2]['original']; ?>">
        <?php echo "<img src='".$image['client_image'][3]['thumb']."' />" ;?>
      </a>
     <div class="tooltip">
      <h5>Resolution</h5>
      <p>[ORIGINAL RESOLUTION]</p>
      <h5>Credit</h5>
      <p><?php echo $image['client_image_credit'][4]; ?></p>
      <h5>Description</h5>
      <p><?php echo $image['client_image_description'][5]; ?></p>
    </div>
  </div>
    <?php }
  ?>

Where it says [ORIGINAL RESOLUTION], I'd like to print the resolution (e.g. "1200x800") of the source image.

Magic Fields uses phpThumb to generate thumbnails. phpThumb seems to have a function for this purpose:

//Getting the original size of the image
if( preg_match('/'.MF_FILES_NAME.'/',$image_name_clean) ){
  $image_name_clean = preg_replace('/'.MF_FILES_NAME.'\//','',$image_name_clean);
  $file = MF_FILES_DIR.$image_name_clean;
}else{
  $file = WP_CONTENT_DIR.DS.$image_name_clean;
}

if(file_exists($file) && (empty($_GET['w']) || empty($_GET['h']))){
    $size = @getimagesize($file);
    $default['w'] = $size[0];
    $default['h'] = $size[1];
}

Would anyone be able to help me connect the dots? Thanks!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I have worked many times with timthumb, but I do not know magic fields, and I am sorry, but i fail to understand a few things :

  1. you want to put a FULL resolution inside a tooltip ?
  2. does thispart of your code $image['client_image'][2]['original']; from above works ?
  3. if it does, there is no reason it should not work in the other div .

anyhow , you can pass parameters to timthumb directly for example like so :

define the variable with a URL

$thumb_for_tim = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ) ; // or in your case - your custom field value - if it returns a URL

and then call it

<img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $thumb_for_tim; ?>&amp;h=155&amp;w=180&amp;zc=1&amp;f=2" alt="<?php the_title(); ?>" h & w are the height and width ..

EDIT ok, after your comment it is more clear . at first when you wrote "[ORIGINAL RESOLUTION]" I thought you wanted the image itself. in that case the answer is much simpler . PHP has a special function for that .

getimagesize()

$size = getimagesize($filename);

so just point the URL of the image to $filename;

FYI - wordpress itself has a function to get imagesize , it is called

wp_get_attachment_image_src

use like so :

$image_attributes = wp_get_attachment_image_src( $attachment->ID,full ); 

it will returns an array

  • [0] => url
  • 1 => width
  • [2] => height

    so echo $image_attributes[1]; will give you width, and $image_attributes[2] will give you height...

share|improve this answer
    
I'm not trying to display the image inside the tooltip, but rather the dimensions of the image. The thumbnail links to the full sized image, and the tooltip tells the user what the resolution of that image is, e.g., "1200px x 800px" –  Ben L Dec 6 '11 at 21:37
    
see my modified answer . –  krembo99 Dec 7 '11 at 2:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.