function feeds_imagegrabber_is_image in Feeds Image Grabber 6
Same name and namespace in other branches
- 7 feeds_imagegrabber.module \feeds_imagegrabber_is_image()
Checks that a file is an image.
This check allows the image formats identified by drupal i.e. jpeg, png and gif. If the filename is missing an extension but is a valid image, its actual extension is added to it.
Parameters
$filepath: The path to the image file.
Return value
The final path to the image file, it may be modified or FALSE on failure.
1 call to feeds_imagegrabber_is_image()
- feeds_imagegrabber_feeds_set_target in ./
feeds_imagegrabber.module - Implementation of hook_feeds_set_target().
File
- ./
feeds_imagegrabber.module, line 571 - Grabs image for each feed-item from their respective web pages and stores it in an image field. Requires Feeds module.
Code
function feeds_imagegrabber_is_image($filepath) {
$extensions = 'jpeg jpg png gif';
if ($filepath) {
$info = feeds_imagegrabber_get_image_info($filepath);
if ($info && !empty($info['extension'])) {
if (!count(feeds_imagegrabber_validate_extensions($filepath, $extensions))) {
return $filepath;
}
else {
$basename = basename($filepath);
$directory = dirname($filepath);
if ($pos = strrpos($basename, '.')) {
$name = substr($basename, 0, $pos);
$ext = substr($basename, $pos);
$regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')/i';
if (preg_match($regex, $ext, $matches)) {
$ext = $matches[1];
}
else {
$ext = $info['extension'];
}
$basename = $name . '.' . $ext;
}
else {
$basename .= '.' . $info['extension'];
}
if ($basename == basename($filepath)) {
return $filepath;
}
$dest = $directory . '/' . $basename;
if (rename($filepath, $dest)) {
return $dest;
}
}
}
}
return FALSE;
}