function media_watermark_create_image in Media watermark 7
Function to create image (.jpg, .jpeg, .png, .gif) file.
Parameters
string $file_path: temporary path of uploaded file
array $form_state: array of form state
2 calls to media_watermark_create_image()
- media_watermark_add_watermark in ./
media_watermark.module - Callback to add watermark.
- media_watermark_process_multiple_images in ./
media_watermark.module - Batch worker function.
File
- ./
media_watermark.module, line 202 - Watermark media module.
Code
function media_watermark_create_image($file_path, $form_state) {
$watermark_obj = db_query("SELECT * FROM {media_watermark} WHERE fid = :fid", array(
':fid' => $form_state['values']['watermarks_names'],
));
$watermark_obj = $watermark_obj
->fetchObject();
$watermark_file = file_load($watermark_obj->fid);
$watermark_filepath = drupal_realpath($watermark_file->uri);
$watermark_extension = pathinfo($watermark_filepath, PATHINFO_EXTENSION);
// Check uploaded image extension.
$ext = pathinfo($file_path, PATHINFO_EXTENSION);
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = imagecreatefromjpeg($file_path);
}
elseif ($ext == 'png') {
$img = imagecreatefrompng($file_path);
}
elseif ($ext == 'gif') {
$img = imagecreatefromgif($file_path);
}
if (!empty($img)) {
ob_start();
if ($watermark_extension == 'png') {
$watermark_img = imagecreatefrompng($watermark_filepath);
}
elseif ($watermark_extension == 'gif') {
$watermark_img = imagecreatefromgif($watermark_filepath);
}
module_load_include('inc', 'media_watermark', 'includes/media_watermark');
$watermark = new MediaWatermark();
$im = $watermark
->addWatermark($img, $watermark_img, $watermark_obj, $ext);
imagepng($im, $file_path);
imagedestroy($im);
ob_end_clean();
}
}