Discussions


Chess, Go & Poker Server









                                          
User   Password   remember   (register)  ?

Php (fr)

Search in  php (fr)  forum  
New topic
  Smilies

Guest name   (optional)       Register for options.


Changer la taille d'une image GIF en PHP       (0)     2010-05-22

Salut à tous, voici un petit script que je trouve très utile (pas si évident que ça à trouver sur le net, d'autres ne marchaient pas) et qui vous permettra de change (...)




Display  archives , all threads.        


Search this category  


Follow the news in the forum     RSS feed



Last post in this thread :


guest-sabodo    (2010-05-22 14:36:47)
Changer la taille d'une image GIF en PHP

Salut à tous, voici un petit script que je trouve très utile (pas si évident que ça à trouver sur le net, d'autres ne marchaient pas) et qui vous permettra de changer la taille d'une image GIF (ou JPG, PNG...) tout en maintenant (en récréant) la transparence d'origine.

rename($_FILES['image']['tmp_name'], $image_path);

// chmod($image_path,0755);  pas forcément utile

list($photo_width,$photo_height) = getimagesize($image_path);
// [1] width [2] height [3] type
 
if ($img_size[2] == 1) $photo_resource = imagecreatefromgif($image_path);  // 1:GIF
elseif ($img_size[2] == 3) $photo_resource = imagecreatefrompng($image_path);  // 3:PNG
else $photo_resource = imagecreatefromjpeg($image_path);  // 2:JPG

$photo_resource_resized = imagecreatetruecolor($new_width, $new_height);

if ($img_size[2] == 1)  // Cas des images GIF
{
  $originaltransparentcolor = imagecolortransparent( $photo_resource );
  if ($originaltransparentcolor >= 0 && $originaltransparentcolor < imagecolorstotal($photo_resource))
{
  $transparentcolor = imagecolorsforindex( $photo_resource, $originaltransparentcolor );
  $newtransparentcolor = imagecolorallocate($photo_resource_resized, $transparentcolor['red'], $transparentcolor['green'],$transparentcolor['blue']);
  imagefill( $photo_resource_resized, 0, 0, $newtransparentcolor );
  imagecolortransparent( $photo_resource_resized, $newtransparentcolor );
}
}

imagecopyresampled($photo_resource_resized, $photo_resource, 0, 0, 0, 0, $new_width, $new_height, $photo_width, $photo_height);
 
if ($img_size[2] == 1) imagegif($photo_resource_resized,$image_path);
elseif ($img_size[2] == 3) imagepng($photo_resource_resized,$image_path);
else imagejpeg($photo_resource_resized,$image_path);


Et voilà le travail, maintenant vos utilisateurs pourront uploader des images gif que vos scripts pourront modifier sans les altérer.









 
 


Q / A : You may write any question (and answer) in 10 languages :


Photo blog selected : lol

lol - August 29, 2012   lol - August 28, 2012   lol - August 27, 2012  
A new picture tomorrow morning, around 10 a.m.



 


Write upside down to your friends!   In your blog, anywhere...
(works with MySpace, Twitter, Facebook, Youtube, MSN, Hi5, Bebo, Yahoo...)






Tip of the day :

Promote your website & protect your Uptobox, Mega or Mediafire links !

Here is the simplest tool : Protect your links




FICGS is also a Free Internet Correspondence Games Server.

Here you can play Chess (Schach, Scacchi, Ajedrez, Xadrez, Satranc, Шахматы, Cờ vua, หมากรุกสากล, 國際象棋, शतरंज, 체스), Go (围棋, 바둑, 囲碁, Cờ vay, Го, wei'chi, baduk) & Poker Texas Holdem (Poquer, Покер, 撲克, 포커) online for free in rated class tournaments and a unique world championship. Special events (chess 960) and tournaments with money prizes are also organized.

Free Internet Chess & Go Server


Feel free to link to this page and to FICGS chess server :