$default_image = array('width' => $width, 'height' => $height, 'filepath' => (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $site->CONF['hostname'] . $site->CONF['wwwroot'] . '/' . str_replace($site->absolute_path, '', $object->all['fullpath']), 'name' => $site->sys_sona(array('sona' => 'original picture', 'tyyp' => 'Editor')) . ' (' . $width . 'x' . $height . ')'); $definitions = array(); $sql = 'select definition_id, value, name from config_images order by value desc'; $result = new SQL($sql); while ($row = $result->fetch('ASSOC')) { $definitions[$row['definition_id']]['width'] = $row['value']; $definitions[$row['definition_id']]['name'] = $row['name']; if (!$definitions[$row['definition_id']]['width'] || $definitions[$row['definition_id']]['width'] > $width) { unset($definitions[$row['definition_id']]); } else { $definitions[$row['definition_id']]['height'] = round($height / ($width / $definitions[$row['definition_id']]['width'])); $definitions[$row['definition_id']]['name'] = $site->sys_sona(array('sona' => 'image_definitions_' . $definitions[$row['definition_id']]['name'], 'tyyp' => 'Custom')) . ' (' . $definitions[$row['definition_id']]['width'] . 'x' . $definitions[$row['definition_id']]['height'] . ')'; $pathinfo = pathinfo($object->all['fullpath']); $image_path = str_replace($site->absolute_path, '', $object->all['fullpath']); // create images $image = new ImageShopper($image_path); $image->file_name_body_add = '_' . $definitions[$row['definition_id']]['width'] . 'x' . $definitions[$row['definition_id']]['height']; $image->file_auto_rename = false; $image->image_resize = true; $image->image_x = $definitions[$row['definition_id']]['width']; $image->image_y = $definitions[$row['definition_id']]['height']; $image->process($pathinfo['dirname'] . '/.thumbnails'); if (file_exists($image->file_dst_pathname)) { $definitions[$row['definition_id']]['filepath'] = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $site->CONF['hostname'] . $site->CONF['wwwroot'] . '/' . str_replace($site->absolute_path, '', $image->file_dst_pathname); } else { unset($definitions[$row['definition_id']]); //printr($image->log); } } } $definitions[] = $original_image = $default_image;
/** * Creates a thumbnail of from an image * * @param string $fullpath */ function create_file_thumbnail($fullpath) { global $site, $class_path; include_once $class_path . 'picture.inc.php'; // Check if Thumbnail directory exists if (!is_dir(dirname(realpath($fullpath)) . '/.thumbnails')) { $mask = umask(0); mkdir(dirname(realpath($fullpath)) . '/.thumbnails', 0777); umask($mask); } $pathinfo = pathinfo($fullpath); if (preg_match("/(jpeg|pjpeg|jpg|png|gif)/i", $pathinfo['extension'])) { $thumb_max_size = 95; $image = new ImageShopper(str_replace($site->absolute_path, '', $fullpath)); //Get file Info $cur_x = $image->image_src_x; $cur_y = $image->image_src_y; //Calculate thumb size $image_rate = max($cur_x / $thumb_max_size, $cur_y / $thumb_max_size); $new_x = round($cur_x / $image_rate); $new_y = round($cur_y / $image_rate); $image->image_resize = true; $image->image_x = $new_x; $image->image_ratio_y = true; $image->file_auto_rename = false; $image->process($pathinfo['dirname'] . '/.thumbnails'); @chmod($pathinfo['dirname'] . '/.thumbnails/' . $pathinfo['basename'], 0666); } }
function generate_images($path, $thumb_width, $pic_width) { global $site; if (!is_dir($path)) { //ei ole kataloog //printr('//ei ole kataloog'); return false; } if (!is_dir($path . '/.gallery_thumbnails')) { if (!mkdir($path . '/.gallery_thumbnails')) { new Log(array('action' => 'create', 'type' => 'ERROR', 'component' => 'Gallery', 'message' => 'Could not create folder for thumbnails in ' . str_replace($site->absolute_path, '', $path))); return false; } } if (!is_dir($path . '/.gallery_pictures')) { if (!mkdir($path . '/.gallery_pictures')) { new Log(array('action' => 'create', 'type' => 'ERROR', 'component' => 'Gallery', 'message' => 'Could not create folder for pictures in ' . str_replace($site->absolute_path, '', $path))); return false; } } //on kataloog ja .gallery_thumbnails ja .gallery_pictures on olemas $filenames = array(); $dir_handle = opendir($path); while (false !== ($filename = readdir($dir_handle))) { if ($filename == '.' || $filename == '..') { } else { if (!is_dir($path . '/' . $filename)) { $filenames[] = $filename; } } } foreach ($filenames as $file) { if (file_exists($path . '/.gallery_thumbnails/' . $file)) { if (filesize($path . '/.gallery_thumbnails/' . $file)) { $thumb_data = getimagesize($path . '/.gallery_thumbnails/' . $file); if ($thumb_data[0] != $thumb_width) { $gen_thumb = true; } else { $gen_thumb = false; } } else { $gen_thumb = true; } } elseif (getimagesize($path . '/' . $file)) { $gen_thumb = true; } else { $gen_thumb = false; } if (file_exists($path . '/.gallery_pictures/' . $file)) { if (filesize($path . '/.gallery_pictures/' . $file)) { $image_data = getimagesize($path . '/.gallery_pictures/' . $file); if ($image_data[0] != $pic_width) { $gen_pic = true; } else { $gen_pic = false; } } else { $gen_pic = true; } } elseif (getimagesize($path . '/' . $file)) { $gen_pic = true; } else { $gen_pic = false; } //$gen_thumb = true; //$gen_pic = true; if ($gen_pic || $gen_thumb) { //recreate thumbnail $args = array(); $args['file'] = $path . '/' . $file; if ($gen_thumb) { $args['thumb'] = $path . '/.gallery_thumbnails/' . $file; $args['thumb_width'] = $thumb_width; } if ($gen_pic) { $args['image'] = $path . '/.gallery_pictures/' . $file; $args['image_width'] = $pic_width; } $args['no_unlink'] = true; //$image_data=picture_resize(0,array(),$args); if ($gen_thumb) { $image = new ImageShopper(str_replace($site->absolute_path, '', $args['file'])); $cur_x = $image->image_src_x; $cur_y = $image->image_src_y; $image_rate = max($cur_x / $args['thumb_width'], $cur_y / $args['thumb_width']); $new_x = round($cur_x / $image_rate); $new_y = round($cur_y / $image_rate); $image->image_resize = true; $image->image_x = $new_x; $image->image_ratio_y = true; $image->file_auto_rename = false; $image->file_overwrite = true; $image->process($path . '/.gallery_thumbnails'); //printr($image->log); if (!file_exists($image->file_dst_pathname)) { new Log(array('action' => 'create', 'type' => 'ERROR', 'component' => 'Gallery', 'message' => 'Could not create thumbnail for ' . $path . '/' . $file)); } unset($image); } if ($gen_pic) { $image = new ImageShopper(str_replace($site->absolute_path, '', $args['file'])); $cur_x = $image->image_src_x; $cur_y = $image->image_src_y; $image_rate = max($cur_x / $args['image_width'], $cur_y / $args['image_width']); $new_x = round($cur_x / $image_rate); $new_y = round($cur_y / $image_rate); $image->image_resize = $image_rate > 1 ? true : false; $image->image_x = $new_x; $image->image_ratio_y = true; $image->file_auto_rename = false; $image->file_overwrite = true; $image->process($path . '/.gallery_pictures'); //printr($image->log); if (!file_exists($image->file_dst_pathname)) { new Log(array('action' => 'create', 'type' => 'ERROR', 'component' => 'Gallery', 'message' => 'Could not create thumbnail for ' . $path . '/' . $file)); } unset($image); } } } return true; }