Image Styles Generate
A derivative image is generated on the fly when served over HTTP. When the derivative image is requested in HTTP, if the file doesn't exists, the HTTP request is handled by Drupal. Drupal will use the image_style_deliver() page callback to generate the derivative image and deliver it. Once the image exists, Drupal will not handle the request and the file is directly delivered.

If you need to access to files externally without using HTTP to access them, you can use image_style_create_derivative($style, $source, $destination) to create the derivatives images. You will need to provide the destination path for the derivative image, which you can get with the image_style_path($style_name, $uri) function.

The following (untested) code should ensure that the derivatives for the image file identified by $fid are generated for the styles whose names are in the $styles array.

$original = file_load($fid);
foreach ($styles as $style_name) {
  $derivative_uri = image_style_path($style_name, $original-&gt;uri);
  image_style_create_derivative($style_name, $original-&gt;uri, $derivative_uri);
}