Changeset 10686 for trunk/include/ws_functions.inc.php
- Timestamp:
- Apr 29, 2011, 7:38:59 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/ws_functions.inc.php
r10653 r10686 2659 2659 } 2660 2660 2661 function ws_images_resize($params, &$service) 2662 { 2663 global $conf; 2664 2661 function ws_images_resizethumbnail($params, &$service) 2662 { 2665 2663 if (!is_admin()) 2666 2664 { … … 2668 2666 } 2669 2667 2670 if (!in_array($params['type'], array('thumbnail', 'websize')))2671 {2672 return new PwgError(403, 'Unknown type (only "thumbnail" or "websize" are accepted');2673 }2674 2675 2668 if (empty($params['image_id']) and empty($params['image_path'])) 2676 2669 { … … 2678 2671 } 2679 2672 2680 $resize_params = array('maxwidth', 'maxheight', 'quality', 'crop', 'follow_orientation');2681 $type = $params['type'] == 'thumbnail' ? 'thumb' : 'websize';2682 foreach ($resize_params as $param)2683 {2684 if (empty($params[$param]) and isset($conf['upload_form_'.$type.'_'.$param]))2685 $params[$param] = $conf['upload_form_'.$type.'_'.$param];2686 }2687 2688 include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');2689 2673 include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); 2690 2674 include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); … … 2706 2690 $image_path = $image['path']; 2707 2691 $thumb_path = get_thumbnail_path($image); 2708 $hd_path = get_high_path($image);2709 2692 } 2710 2693 else … … 2712 2695 $image_path = $params['image_path']; 2713 2696 $thumb_path = file_path_for_type($image_path, 'thumb'); 2714 $hd_path = file_path_for_type($image_path, 'high'); 2715 } 2716 2717 if (!is_valid_image_extension(get_extension($image_path))) 2697 } 2698 2699 if (!file_exists($image_path) or !is_valid_image_extension(get_extension($image_path))) 2718 2700 { 2719 2701 return new PwgError(403, "image can't be resized"); … … 2721 2703 2722 2704 $result = false; 2723 2724 if ($params['type'] == 'thumbnail' and file_exists($image_path)) 2725 { 2726 prepare_directory(dirname($thumb_path)); 2727 2728 $img = new pwg_image($image_path, $params['library']); 2729 2730 $result = $img->pwg_resize( 2731 $thumb_path, 2732 $params['maxwidth'], 2733 $params['maxheight'], 2734 $params['quality'], 2735 $params['automatic_rotation'], 2736 true, 2737 get_boolean($params['crop']), 2738 get_boolean($params['follow_orientation']) 2739 ); 2740 2741 $img->destroy(); 2742 } 2743 elseif (file_exists($hd_path)) 2744 { 2745 $img = new pwg_image($hd_path); 2746 2747 $result = $img->pwg_resize( 2748 $image_path, 2749 $params['maxwidth'], 2750 $params['maxheight'], 2751 $params['quality'], 2752 $params['automatic_rotation'], 2753 false 2754 ); 2755 2756 $img->destroy(); 2757 2758 if (!empty($image['has_high'])) 2759 { 2760 $conf['use_exif'] = false; 2761 $conf['use_iptc'] = false; 2762 update_metadata(array($image['id'] => $image['path'])); 2763 } 2764 } 2705 prepare_directory(dirname($thumb_path)); 2706 $img = new pwg_image($image_path, $params['library']); 2707 2708 $result = $img->pwg_resize( 2709 $thumb_path, 2710 $params['maxwidth'], 2711 $params['maxheight'], 2712 $params['quality'], 2713 false, // automatic rotation is not needed for thumbnails. 2714 true, // strip metadata 2715 get_boolean($params['crop']), 2716 get_boolean($params['follow_orientation']) 2717 ); 2718 2719 $img->destroy(); 2720 return $result; 2721 } 2722 2723 function ws_images_resizewebsize($params, &$service) 2724 { 2725 if (!is_admin()) 2726 { 2727 return new PwgError(401, 'Access denied'); 2728 } 2729 2730 include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 2731 include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); 2732 include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); 2733 2734 $query=' 2735 SELECT id, path, tn_ext, has_high 2736 FROM '.IMAGES_TABLE.' 2737 WHERE id = '.(int)$params['image_id'].' 2738 ;'; 2739 $image = pwg_db_fetch_assoc(pwg_query($query)); 2740 2741 if ($image == null) 2742 { 2743 return new PwgError(403, "image_id not found"); 2744 } 2745 2746 $image_path = $image['path']; 2747 $hd_path = get_high_path($image); 2748 2749 if (empty($image['has_high']) or !file_exists($hd_path) or !is_valid_image_extension(get_extension($image_path))) 2750 { 2751 return new PwgError(403, "image can't be resized"); 2752 } 2753 2754 $result = false; 2755 $img = new pwg_image($hd_path); 2756 2757 $result = $img->pwg_resize( 2758 $image_path, 2759 $params['maxwidth'], 2760 $params['maxheight'], 2761 $params['quality'], 2762 $params['automatic_rotation'], 2763 false // strip metadata 2764 ); 2765 2766 $img->destroy(); 2767 2768 global $conf; 2769 $conf['use_exif'] = false; 2770 $conf['use_iptc'] = false; 2771 update_metadata(array($image['id'] => $image['path'])); 2772 2765 2773 return $result; 2766 2774 }
Note: See TracChangeset
for help on using the changeset viewer.