Voilà j'ai crée une classe image.
La voici:
<?php
class Image
{
var $img_id; // Id de l'image
var $img; // Nom de l'image
var $type_resize; // Type de réduction -- small ou big
var $degres; // Angle de rotation
var $error; // Variable pour les erreurs
/*
@ Constante de la classe
*/
// Taille des images dans la liste
const MAX_SMALL_WIDTH = 150;
const MAX_SMALL_HEIGHT = 150;
// Taille des images dans la liste
const MAX_BIG_WIDTH = 300;
const MAX_BIG_HEIGHT = 300;
// Réglage des qualités
const QUALITY_JPEG = 100; // Pour les jpeg -- Valeur comprise entre 0 et 100
const QUALITY_PNG = 7; // Pour les png -- Valeur comprise entre 0 et 10
// Réglage des écritures
const TEXT_ANGLE = 0;
const TEXT_POLICE = "arial.ttf";
const TEXT_SIZE = 12;
const TEXT = "Copyright 2008";
// Réglage pour small
const TEXT_CORD_Y_SMALL = 140;
const TEXT_CORD_X_SMALL = 5;
// Réglage pour big
const TEXT_CORD_Y_BIG = 290;
const TEXT_CORD_X_BIG = 5;
/*
@ Fonction qui détermine la hauteur de l'image
@
@ $image = Nom de l'image
*/
private function Get_Image_Height($image)
{
$this->list_img = getimagesize($image);
return $this->list_img[1];
}
/*
@ Fonction qui détermine la largeur de l'image
@
@ $image = Nom de l'image
*/
private function Get_Image_Width($image)
{
$this->list_img = getimagesize($image);
return $this->list_img[0];
}
/*
@ Fonction qui détermine le type de l'image
@
@ $image = Nom de l'image
*/
private function Get_Image_Type($image)
{
$this->list_img = getimagesize($image);
return $this->list_img[2];
}
/*
@ Fonction de création du nouveau nom de l'image
@
@ $image = Nom de l'image
*/
private function Get_Image_Name($image, $type)
{
$this->name_img = strtolower($image);
$this->name_img = substr($this->name_img, 0, -4);
switch($type)
{
case 1:
$this->ext = '.gif';
break;
case 2:
$this->ext = '.jpeg';
break;
case 3:
$this->ext = '.png';
break;
}
return $this->name_img.$this->ext;
}
/*
@ Fonction qui détermine le nom de l'image
@
@ $image = Nom de l'image
*/
private function Get_Data_Image_Name($image)
{
$this->name_img = strtolower($image);
$this->name_img = substr($this->name_img, 0, -4);
return $this->name_img;
}
/*
@ Fonction qui détermine le type de header a utiliser
@
@ $image = Nom de l'image
*/
private function Get_Image_Header($type, $image)
{
switch($type)
{
case 1:
header('Content-type: image/gif');
break;
case 2:
header('Content-type: image/jpeg');
break;
case 3:
header('Content-type: image/png');
break;
}
}
/*
@ Fonction d'affichage de l'image
@
@ $image = Nom de l'image
*/
private function Get_Image_Save($type, $image)
{
switch($type)
{
case 1:
imagegif($image);
break;
case 2:
imagejpeg($image, '', self::QUALITY_JPEG);
break;
case 3:
imagepng($image);
break;
}
}
/*
@ Fonction qui libere la mémoire
@
@ $image = Nom de l'image
*/
private function Get_Image_Destroy($type, $image)
{
imagedestroy($image.$type);
}
/*
@ Fonction d'erreur
*/
public function Get_Message_Error($error)
{
if(!empty($error))
{
echo $error;
}
}
/*
@ Fonction d'affichage d'image
*/
public function Write()
{
$this->width = $this->Get_Image_Width($this->img);
$this->height = $this->Get_Image_Height($this->img);
$this->type = $this->Get_Image_Type($this->img);
if($this->type_resize == 'small')
{
$max_width = self::MAX_SMALL_WIDTH;
$max_height = self::MAX_SMALL_HEIGHT;
}
elseif($this->type_resize == 'big')
{
$max_width = self::MAX_BIG_WIDTH;
$max_height = self::MAX_BIG_HEIGHT;
}
$this->Get_Image_Header($this->type, $this->img);
$thumb = imagecreatetruecolor($max_width, $max_height);
switch($this->type)
{
case 1:
$source = imagecreatefromgif($this->img);
break;
case 2:
$source = imagecreatefromjpeg($this->img);
break;
case 3:
$source = imagecreatefrompng($this->img);
break;
}
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $max_width, $max_height, $this->width, $this->height);
$this->Get_Image_Save($this->type, $thumb);
$this->Get_Image_Destroy($this->type, $thumb);
}
/*
@ Fonction de réduction d'image
*/
public function Resize()
{
$this->width = $this->Get_Image_Width($this->img);
$this->height = $this->Get_Image_Height($this->img);
$this->type = $this->Get_Image_Type($this->img);
if($this->type_resize == 'small')
{
$max_width = self::MAX_SMALL_WIDTH;
$max_height = self::MAX_SMALL_HEIGHT;
$coordonnee_x = self::TEXT_CORD_X_SMALL;
$coordonnee_y = self::TEXT_CORD_Y_SMALL;
}
elseif($this->type_resize == 'big')
{
$max_width = self::MAX_BIG_WIDTH;
$max_height = self::MAX_BIG_HEIGHT;
$coordonnee_x = self::TEXT_CORD_X_BIG;
$coordonnee_y = self::TEXT_CORD_Y_BIG;
}
if($this->width >= $max_width)
{
if($this->height >= $max_height)
{
$new_w = $max_width;
$new_h = $max_height;
}
else
{
$new_w = $max_width;
$new_h = $this->height;
}
}
elseif($this->height >= $max_height)
{
$new_w = $this->width;
$new_h = $max_height;
}
$this->Get_Image_Header($this->type, $this->img);
$thumb = imagecreatetruecolor($new_w, $new_h);
switch($this->type)
{
case 1:
$source = imagecreatefromgif($this->img);
break;
case 2:
$source = imagecreatefromjpeg($this->img);
break;
case 3:
$source = imagecreatefrompng($this->img);
break;
}
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_w, $new_h, $this->width, $this->height);
$couleur = ImageColorAllocate($thumb, 221, 221, 221);
imagettftext(
$thumb,
self::TEXT_SIZE,
self::TEXT_ANGLE,
$coordonnee_x,
$coordonnee_y,
$couleur,
self::TEXT_POLICE,
self::TEXT
);
$this->Get_Image_Save($this->type, $thumb);
$this->Get_Image_Destroy($this->type, $thumb);
}
/*
@ Fonction de rotation d'image
*/
public function Rotate()
{
$this->type = $this->Get_Image_Type($this->img);
$this->Get_Image_Header($this->type, $this->img);
if($this->type_resize == 'small')
{
$coordonnee_x = self::TEXT_CORD_X_SMALL;
$coordonnee_y = self::TEXT_CORD_Y_SMALL;
}
elseif($this->type_resize == 'big')
{
$coordonnee_x = self::TEXT_CORD_X_BIG;
$coordonnee_y = self::TEXT_CORD_Y_BIG;
}
switch($this->type)
{
case 1:
$source = imagecreatefromgif($this->img);
break;
case 2:
$source = imagecreatefromjpeg($this->img);
break;
case 3:
$source = imagecreatefrompng($this->img);
break;
}
$thumb = imagerotate($source, $this->degres, 0);
$couleur = ImageColorAllocate($thumb, 0, 0, 0);
imagettftext(
$thumb,
self::TEXT_SIZE,
self::TEXT_ANGLE,
$coordonnee_x,
$coordonnee_y,
$couleur,
self::TEXT_POLICE,
self::TEXT
);
$this->Get_Image_Save($this->type, $thumb);
$this->Get_Image_Destroy($this->type, $thumb);
}
/*
@ Fonction d'affichage du descriptif de l'image
*/
public function Data_Info()
{
global $db;
$sql = "select * from ".TABLE_PHOTO." where photo_id = '".$this->img_id."'";
$req = $db->sql_query($sql);
$row = $db->sql_fetch_array($req);
$this->width = $this->Get_Image_Width($row['photo_link']);
$this->height = $this->Get_Image_Height($row['photo_link']);
$this->type = $this->Get_Image_Type($row['photo_link']);
$list[$i]['photo_name'] = $row['photo_name'];
$list[$i]['photo_author'] = $row['photo_author'];
$list[$i]['photo_desc'] = $row['photo_desc'];
$list[$i]['photo_date'] = $row['photo_date'];
$list[$i]['photo_width'] = $this->width;
$list[$i]['photo_height'] = $this->height;
$list[$i]['photo_type'] = $this->type;
$list[$i]['photo_view'] = $row['photo_view'];
return array($list);
}
}
?>
Le problème est que lorsque j'exécute cette url: http://www.monsite.fr/show.php?file=1&mode=resizeCela ne m'affiche rien.
Voici le contenu de mon fichier show.php
<?php
include('inc/class/class_mysql.php');
include('inc/config.php');
include('inc/function/constant.php');
include('inc/class/class_image.php');
$db = new Sql();
$db->sql_connect($host, $login_host, $pass_host, $hostname);
$file = $_GET['file'];
$mode = $_GET['mode'];
$ang = $_GET['ang'];
$sql = "select * from ".TABLE_PHOTO." where photo_id = '".$file."'";
if( !($req = $db->sql_query($sql)) )
{
$db->sql_error(TABLE_FOLDER, 'sql_query()', __LINE__, __FILE__, $sql, mysql_error());
}
$row = $db->sql_fetch_array($req);
$file_link = $row['photo_link'];
if($ang == '')
{
$angle = 0;
}
elseif($ang == 1)
{
$angle = 90;
}
elseif($ang == -1)
{
$angle = -90;
}
elseif($ang == 0)
{
$angle = 180;
}
$image = new Image;
$image->img = $file_link;
$image->degres = $angle;
$image->type_resize = "big";
switch($mode)
{
case 'rotate':
$image->Rotate();
break;
case 'resize':
$image->Resize();
break;
}
?>
Quand je fais:
echo $file_link;
J'obtiens bien ce qui est stockés dans ma bdd donc un lien comme ceci: upload/dossier_01/01.JPGEt quand je met ce lien dans mon url je vois bien l'image donc pourquoi je n'arrive pas à l'afficher avec ma classe surtout que c'est pareil avec les fonctions Write() et Rotate().
Merci d'avance...