Créer son site Gratuitement : Service / Outils webmaster gratuit
Mon Site Gratuit
Contactez nous
Nos partenaires
Scripts
Tutoriaux
Nos services
Forums
Accueil
ForumsPHP : Afficher des informations image
      Imprimer le sujet FAQ  M'enregistrer 
  Dynamisez facilement votre site internet grace à notre gamme de scripts PHP de toutes sortes créé par nos amis Plug'ziens pour satisfaire vos besoins

PHP : Afficher des informations image

Messagede zardoz le 11 Oct 2008, 23:50

Comme dans tous les langages de programmations, il se peut que nous n'ayons besoin que d'information sur un objet. Ceci est fréquent lors du développement d'une application et PHP n'échappe pas à la règle.

Voici le script : Niveau débutant.
Ce script n'aura de but que de charger les informations d'un objet cible.

Code: Tout sélectionner
<?php
function cibleInfos($url)
{
  // ..
  // .. Variable de mise en page ..
  // ..
  $br = "<br />";
  // ..
  // .. Variable essentielle
  // .. $url est la cible à manipuler
  // .. $informations l'objet Array à interroger ..
  // ..
  $informations = getimagesize($url);
  // ..
  // .. Le type affecté à la variable avec la fonction getimagesize() ..
  // .. est un toujours un array : $informations est-il de type Array ? ..
  // ..
  if (is_array($informations))
  {
    // .. On vérifie le type d'objet ..
   // ..
    echo "Le type d'objet \$informations est un : " . $informations . $br;
   // ..
   // .. Les différentes informations sur l'image cibler ..
   // ..
   print_r($informations); echo $br.$br;
  // ..
  // .. On affiche les informations de l'image ..
  // ..   
  echo "Index [0] - Largeur (int) : " . $informations[0] . $br;
  echo "Index [1] - Hauteur (int) : " . $informations[1] . $br;
  echo "Index [2] - Type Image (int) : " . $informations[2] . $br;
  echo "Index [3] - Attributs HTML (string) : " . $informations[3] . $br;
  echo "Index [bits] - Bits (int) : " . $informations['bits'] . $br;
  echo "Index [channels] - Cannaux (int) : " . $informations['channels'] . $br;
  echo "Index [mime] - Type mime (string) : " . $informations['mime'] . $br;
  }
  else
  {
    echo "Le type d'objet n'est pas un array.";
  }
}
// ..
// .. Appelle de la fonction ..
// ..
cibleInfos("images/Signature_01a.jpg");
?>


Voici les résultats d'affichage :

Le type d'objet $informations est un : Array
Array ( [0] => 615 [1] => 145 [2] => 2 [3] => width="615" height="145" [bits] => 8 [channels] => 3 [mime] => image/jpeg )

Index [0] - Largeur (int) : 615
Index [1] - Hauteur (int) : 145
Index [2] - Type Image (int) : 2
Index [3] - Attributs HTML (string) : width="615" height="145"
Index [bits] - Bits (int) : 8
Index [channels] - Cannaux (int) : 3
Index [mime] - Type mime (string) : image/jpeg

url d'étude : http://ca3.php.net/manual/fr/function.getimagesize.php

;-) ++
Dernière édition par zardoz le 12 Oct 2008, 01:25, édité 2 fois.
zardoz
Plug'zien Star'z
Plug'zien Star'z
 
Messages: 888
Inscription: 16 Fév 2008, 04:05
Points: 582


Re: PHP : Afficher des informations image

Messagede Black le 12 Oct 2008, 00:23

Script encore très utile, mais stp : Arrête d'écrire des pavés résumables en 2 mots ;-D

Par exemple, tu aurais pu dire : Voilà un script permettant d'obtenir des informations sur une image, tel que sa taille/largeur, son extension...

Sinon, tu devrais plutôt mettre ça ici : php-f37.html :regles:

Ah, une autre remarque :
Code: Tout sélectionner
$br = "<br />";
"$br-------------------------------------------------------------------------------------------------------------------------------$br";

Un <hr /> ce serait pas plus simple ? ;-D
Black
Plug'zien Pro
Plug'zien Pro
 
Messages: 1233
Inscription: 08 Déc 2007, 21:34
Localisation: Cherbourg, France.
Points: 856



Retourner vers PHP

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 0 invités