PEEL Shopping
Open source ecommerce : PEEL Shopping
images.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: images.php 46935 2015-09-18 08:49:48Z gboussin $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
33 function image_resize($origin_filename_with_path, $new_filename_with_path, $destinationW = null, $destinationH = null, $resize_even_if_smaller = false, $allow_keep_origin_file_if_resize_not_needed = true, $filesize_limit_keep_origin_file = 102400, $jpeg_quality = 85, $gammacorrect = 1.0)
34 {
35  $origin_file_extension = pathinfo($origin_filename_with_path, PATHINFO_EXTENSION);
36  if (String::strtolower($origin_file_extension) === 'png' && function_exists('imagecreatefrompng')) {
37  $source = @imagecreatefrompng($origin_filename_with_path);
38  } elseif (String::strtolower($origin_file_extension) === 'gif' && function_exists('imagecreatefromgif')) {
39  $source = @imagecreatefromgif($origin_filename_with_path);
40  }
41  if (empty($source) && function_exists('imagecreatefromjpeg')) {
42  // On essaie quoiqu'il arrive de décoder en JPEG
43  $source = @imagecreatefromjpeg($origin_filename_with_path);
44  if (empty($source)) {
45  $source = @imagecreatefrompng($origin_filename_with_path);
46  }
47  }
48  if (empty($source)) {
49  return false;
50  }
51  $sourceW = @imagesx($source);
52  $sourceH = @imagesy($source);
53  if (empty($sourceW) || empty($sourceH)) {
54  return false;
55  }
56  // Zoom par défaut si l'image est plus petite que la limite $image_max_width x $image_max_height
57  $default_zoom = 1;
58 
59  if ((!empty($destinationW) && $sourceW * $default_zoom > $destinationW) || (!empty($destinationH) && $sourceH * $default_zoom > $destinationH) || ((!empty($destinationW) || !empty($destinationH)) && $resize_even_if_smaller)) {
60  if(empty($destinationW)){
61  $destinationW = $sourceW;
62  }
63  if(empty($destinationH)){
64  $destinationH = $sourceH;
65  }
66  if ($sourceH * $destinationW > $destinationH * $sourceW) {
67  // on met au même format que celui de la taille demandée
68  $destinationW = ($sourceW * $destinationH) / $sourceH;
69  } else {
70  $destinationH = ($sourceH * $destinationW) / $sourceW;
71  }
72  } else {
73  $destinationW = $sourceW * $default_zoom;
74  $destinationH = $sourceH * $default_zoom;
75  }
76  if ($destinationW != $sourceW || $destinationH != $sourceH || !$allow_keep_origin_file_if_resize_not_needed || filesize($origin_filename_with_path) > $filesize_limit_keep_origin_file || abs(1-$gammacorrect)>=0.1) {
77  // On crée la nouvelle image seulement si c'est nécessaire, pour ne pas perdre en qualité
78  $im = imagecreatetruecolor($destinationW, $destinationH);
79  // Pour éviter les bordures noires : on remplit de blanc le bord
80  $bg = imagecolorallocate($im, 255, 255, 255);
81  imagefill($im, 0, 0, $bg);
82  // On fait la copie en redimensionnant
83  imagecopyresampled($im, $source, 0, 0, 0, 0, $destinationW, $destinationH, $sourceW, $sourceH);
84  imagedestroy($source);
85  if (abs(1-$gammacorrect)>=0.1) {
86  imagegammacorrect ($im, 1.0, $gammacorrect);
87  }
88  if (!imagejpeg($im, $new_filename_with_path, $jpeg_quality)) {
89  return false;
90  }
91  imagedestroy($im);
92  if ($new_filename_with_path != $origin_filename_with_path) {
93  unlink($origin_filename_with_path);
94  }
95  return $new_filename_with_path;
96  } else {
97  imagedestroy($source);
98  return $origin_filename_with_path;
99  }
100 }
101 
static strtolower($string)
Returns string with all alphabetic characters converted to lowercase.
Definition: String.php:135
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
if(!defined('IN_PEEL')) image_resize($origin_filename_with_path, $new_filename_with_path, $destinationW=null, $destinationH=null, $resize_even_if_smaller=false, $allow_keep_origin_file_if_resize_not_needed=true, $filesize_limit_keep_origin_file=102400, $jpeg_quality=85, $gammacorrect=1.0)
On redimensionne l'image pour qu'elle ne dépasse pas la taille de destination Le ratio largeur / haut...
Definition: images.php:33

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:31:17 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.