You are here

function RealisticDummyContentAttribute::ImageSave in Realistic Dummy Content 7

Return an image file object if possible.

Parameters

$file: The RealisticDummyContentFileGroup object

Return value

NULL if the file is not an image, or if an error occurred; otherwise a Drupal file object.

2 calls to RealisticDummyContentAttribute::ImageSave()
RealisticDummyContentImageField::ValueFromFile_ in api/includes/RealisticDummyContentImageField.inc
Given a RealisticDummyContentFileGroup object, get a structured property
RealisticDummyContentUserPicture::ValueFromFile_ in api/includes/RealisticDummyContentUserPicture.inc
Given a RealisticDummyContentFileGroup object, get a structured property

File

api/includes/RealisticDummyContentAttribute.inc, line 280
Define RealisticDummyContentAttribute autoload class.

Class

RealisticDummyContentAttribute
Represents either a field or a property for an entity.

Code

function ImageSave($file) {
  try {
    $exists = $file
      ->Value();
    if (!$exists) {
      throw new RealisticDummyContentException('Please check if the file exists before attempting to save it');
    }
    $return = NULL;
    if (in_array($file
      ->GetRadicalExtension(), $this
      ->GetImageExtensions())) {
      $return = $this
        ->FileSave($file);
      $alt = $file
        ->Attribute('alt');
      if ($alt) {
        $return->alt = $alt;
      }
    }
    return $return;
  } catch (Exception $e) {
    return NULL;
  }
}