Esempio n. 1
0
 /**
  * Used to resize and watermark image.
  * |= Updated on May 19th, 2012 =|
  * using photo_dimensions filter you can add new
  * dimensions in thumb_dimensions array. Use 
  * add_custom_photo_size() function in your callback
  * to easily add new dimensions
  * */
 function generate_photos($array)
 {
     global $db;
     if (!is_array($array)) {
         $p = $this->get_photo($array);
     } else {
         $p = $array;
     }
     if (!$p) {
         e(lang('Photo does not exist'));
         return false;
     }
     $filename = $p['filename'];
     $extension = $p['ext'];
     $date_dir = get_photo_date_folder($p);
     $path = PHOTOS_DIR . "/" . $date_dir . '/';
     $dimensions = get_photo_dimensions(true);
     $img = new CB_Resizer($path . $filename . "." . $extension);
     foreach ($dimensions as $code => $dim) {
         $img->target = $path . $filename . "_" . $code . "." . $extension;
         // Set cropping
         $img->cropping = $dim['crop'];
         $img->_resize($dim['width'], $dim['height']);
         // Check if we want to sharp this thumb
         if ($dim['sharpit'] == true) {
             $img->_sharpit();
         }
         // Check if we want to apply watermark
         if ($dim['watermark'] == true) {
             // Set placement
             $img->watermark_placement = $this->position;
             $watermark_file = $this->watermark_file();
             // Replacing URL to DIR.
             $watermark = str_replace(BASEURL, BASEDIR, $watermark_file);
             $img->watermark($watermark);
         }
         // Lets save it
         $img->save();
     }
     /* GETTING DETAILS OF IMAGES AND STORING THEM IN DB */
     $this->update_image_details($p);
 }
Esempio n. 2
0
/**
 * Updated version of getting photo file. In this function
 * we dont use glob() function to first get all thumbs and
 * then extract one thumb, instead now we only construct
 * the url of given code/size, checks if file_exists, if yes return
 * thumb else return default thumb.
 */
function get_image_file($params)
{
    global $cbphoto, $Cbucket;
    $details = $params['details'];
    $output = $params['output'];
    $sizes = $params['size'] ? $params['size'] : ($params['code'] ? $params['code'] : 't');
    if (empty($details)) {
        return $cbphoto->default_thumb($size, $output);
    } else {
        // Make sure photo exists
        if (!is_array($details)) {
            $photo = $cbphoto->get_photo($details, true);
        } else {
            $photo = $details;
        }
        if (empty($photo['photo_id']) or empty($photo['photo_key'])) {
            return $cbphoto->default_thumb($size, $output);
        } else {
            if (empty($photo['filename']) or empty($photo['ext'])) {
                return $cbphoto->default_thumb($size, $output);
            } else {
                $params['photo'] = $photo;
                // Call custom functions
                if (count($Cbucket->custom_get_photo_funcs) > 0) {
                    foreach ($Cbucket->custom_get_photo_funcs as $funcs) {
                        if (function_exists($funcs)) {
                            $func_returned = $funcs($params);
                            if ($func_returned) {
                                return $func_returned;
                            }
                        }
                    }
                }
                if ($details['is_mature'] == 'yes' && !userid()) {
                    return get_mature_thumb($details, $size, $output);
                }
                $dir = PHOTOS_DIR;
                $file_directory = get_photo_date_folder($photo);
                $with_path = $params['with_path'] = $params['with_path'] === false ? false : true;
                if ($file_directory) {
                    $file_directory .= '/';
                }
                $path = $dir . '/' . $file_directory;
                $file_name = $photo['filename'] . '%s.' . $photo['ext'];
                $sizes = explode(",", $sizes);
                if ($sizes[0] == 'all' and count($sizes) == 1) {
                    $sizes = get_photo_dimensions(true);
                    $sizes = array_keys($sizes);
                }
                $sizes = array_map("trim", $sizes);
                if (phpversion < '5.2.0') {
                    global $json;
                    $js = $json;
                }
                if (!empty($js)) {
                    $image_details = $js->json_decode($photo['photo_details'], true);
                } else {
                    $image_details = json_decode($photo['photo_details'], true);
                }
                foreach ($sizes as $size) {
                    $filename = sprintf($file_name, "_" . $size);
                    $full_path = $path . $filename;
                    if (file_exists($full_path)) {
                        if ($with_path) {
                            $thumbs[] = PHOTOS_URL . '/' . $file_directory . $filename;
                        } else {
                            $thumbs[] = $filename;
                        }
                    }
                }
                if ($params['with_orig'] === true) {
                    if ($with_path) {
                        $thumbs[] = PHOTOS_URL . '/' . $file_directory . sprintf($file_name, "");
                    } else {
                        $thumbs[] = sprintf($file_name, "");
                    }
                }
                //pr ( $thumbs, true );
                if (!$thumbs or count($thumbs) <= 0) {
                    $thumbs = _recheck_photo_code($params);
                    if (!$thumbs or !is_array($thumbs)) {
                        return $cbphoto->default_thumb($size, $output);
                    }
                }
                if (empty($params['output']) or $params['output'] == 'non_html') {
                    if ($params['assign']) {
                        assign($params['assign'], $thumbs);
                    } else {
                        if ($params['multi']) {
                            return $thumbs;
                        } else {
                            return $thumbs[0];
                        }
                    }
                } else {
                    $attrs = array();
                    $src = $thumbs[0];
                    $size = $cbphoto->get_image_type($src);
                    if (!file_exists(str_replace(PHOTOS_URL, PHOTOS_DIR, $src))) {
                        $src = $cbphoto->default_thumb($size);
                    }
                    if (empty($image_details) or !isset($image_details[$size])) {
                        $dem = getimagesize(str_replace(PHOTOS_URL, PHOTOS_DIR, $src));
                        $width = $dem[0];
                        $height = $dem[1];
                        /* UPDATEING IMAGE DETAILS */
                        $cbphoto->update_image_details($photo);
                    } else {
                        $width = $image_details[$size]['width'];
                        $height = $image_details[$size]['height'];
                    }
                    if ($params['width'] and is_numeric($params['width']) and ($params['height'] and is_numeric($height))) {
                        $width = $params['width'];
                        $height = $params['height'];
                    } else {
                        if ($params['width'] and is_numeric($params['width'])) {
                            $height = round($params['width'] / $width * $height);
                            $width = $params['width'];
                        } else {
                            if ($params['height'] and is_numeric($height)) {
                                $width = round($params['height'] * $width / $height);
                                $height = $p['height'];
                            }
                        }
                    }
                    $attrs['width'] = $width;
                    $attrs['height'] = $height;
                    if ($params['id']) {
                        $id = mysql_clean($params['id']) . "_" . $photo['photo_id'];
                    } else {
                        $id = "photo_" . $photo['photo_id'];
                    }
                    $attrs['id'] = $id;
                    if ($params['class']) {
                        $attrs['class'] = mysql_clean($params['class']);
                    }
                    if ($params['align']) {
                        $attrs['align'] = mysql_clean($params['align']);
                    }
                    $title = $params['title'] ? $params['title'] : $photo['photo_title'];
                    $attrs['title'] = mysql_clean($title);
                    $alt = $params['alt'] ? TITLE . ' - ' . $params['alt'] : TITLE . ' - ' . $photo['photo_title'];
                    $attrs['alt'] = mysql_clean($alt);
                    if (add_tagging_attribute($photo)) {
                        $attrs['cb-tagger-photo'] = 'yes';
                    }
                    $anchor_p = array("place" => 'photo_thumb', "data" => $photo);
                    $params['extra'] = ANCHOR($anchor_p);
                    if ($params['style']) {
                        $attrs['style'] = $params['style'];
                    }
                    if ($params['extra']) {
                        $attrs['extra'] = $params['extra'];
                    }
                    $image = cb_output_img_tag($src, $attrs);
                    if ($params['assign']) {
                        assign($params['assign'], $image);
                    } else {
                        return $image;
                    }
                }
            }
        }
    }
}