How can I get the filesize of an image with an image style programmatically
You can get the size of the original image easily:

$size = filesize($data-&gt;field_field_photo[0]['raw']['uri']);


But the size of an image file behind a derivative path is impossible to get reliably. The files aren't generated until the URL is first visited, so the file may simply not exist yet.

For those that do already exist, you can use image_style_path():

$path = image_style_path('img-lib', $data-&gt;field_field_photo[0]['raw']['uri']);
if (file_exists($path)) {
  $size = filesize($path);
}


If it's 'mission-critical' to get the file size, you can always force-create the derivative there and then with image_style_create_derivative():

$path = image_style_path('img-lib', $data-&gt;field_field_photo[0]['raw']['uri']);
if (file_exists($path)) {
  $size = filesize($path);
}
else {
  if (image_style_create_derivative('img-lib', $data-&gt;field_field_photo[0]['raw']['uri'], $path) === TRUE) {
    $size = filesize($path);
  }
}

if (!isset($size)) {
  // Something went wrong creating the derivative...
}


It's worth noting that you shouldn't do all (or any really) of the above directly in a template file. Instead, move your logic out to a preprocess function and pass variables in.

And if you're looking for full-on 'best practice', instead of accessing the field data directly through the array (e.g. $data-&gt;field_field_photo[0]['raw']['uri']), prefer field_get_items() for procedural-style, or an EntityMetadataWrapper if you're comfortable with OO.