avoir la largeur d'une image
5 messages
• Page 1 sur 1
- silverbeach
- WRInaute occasionnel

- Messages: 333
- Inscription: 20 Juil 2005
avoir la largeur d'une image
Bonjour,
j'ai crée un formulaire pour uploader des images et je voudrai limiter la largeur des images. Donc il faut que je compare la largeur max avec la largeur de l'image.
le problème est que je n'arrive pas a avoir la largeur de l'image
j'ai essayé ce ci :
il me renvoi cette erreur pour les 2 solutions
j'ai crée un formulaire pour uploader des images et je voudrai limiter la largeur des images. Donc il faut que je compare la largeur max avec la largeur de l'image.
le problème est que je n'arrive pas a avoir la largeur de l'image
j'ai essayé ce ci :
- Code: Tout sélectionner
$largeur = imagesx($_FILES['fichier']['tmp_name']);
//et
$largeur = imagesx($_FILES['fichier']['name']);
il me renvoi cette erreur pour les 2 solutions
Warning: imagesx(): supplied argument is not a valid Image resource in c:\documents and settings\***\mes documents\site\***\admin\ajout-image.php on line 52
- zarlboro
- WRInaute occasionnel

- Messages: 284
- Inscription: 13 Juil 2004
getimagesize
(PHP 3, PHP 4, PHP 5)
getimagesize -- Get the size of an image
Description
array getimagesize ( string filename [, array &imageinfo] )
The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, or WBMP image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML <IMG> tag.
If accessing the filename image is impossible, or if it isn't a valid picture, getimagesize() will return FALSE and generate an error of level E_WARNING.
Note: Support for JPC, JP2, JPX, JB2, XBM, and WBMP became available in PHP 4.3.2. Support for SWC exists as of PHP 4.3.0 and TIFF support was added in PHP 4.2.0
Note: JPEG 2000 support was added in PHP 4.3.2. Note that JPC and JP2 are capable of having components with different bit depths. In this case, the value for "bits" is the highest bit depth encountered. Also, JP2 files may contain multiple JPEG 2000 codestreams. In this case, getimagesize() returns the values for the first codestream it encounters in the root of the file.
Note: The getimagesize() function does not require the GD image library.
Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
Example 1. getimagesize (file)
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>
URL support was added in PHP 4.0.5
http://fr.php.net/manual/en/function.getimagesize.php
(PHP 3, PHP 4, PHP 5)
getimagesize -- Get the size of an image
Description
array getimagesize ( string filename [, array &imageinfo] )
The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, or WBMP image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML <IMG> tag.
If accessing the filename image is impossible, or if it isn't a valid picture, getimagesize() will return FALSE and generate an error of level E_WARNING.
Note: Support for JPC, JP2, JPX, JB2, XBM, and WBMP became available in PHP 4.3.2. Support for SWC exists as of PHP 4.3.0 and TIFF support was added in PHP 4.2.0
Note: JPEG 2000 support was added in PHP 4.3.2. Note that JPC and JP2 are capable of having components with different bit depths. In this case, the value for "bits" is the highest bit depth encountered. Also, JP2 files may contain multiple JPEG 2000 codestreams. In this case, getimagesize() returns the values for the first codestream it encounters in the root of the file.
Note: The getimagesize() function does not require the GD image library.
Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
Example 1. getimagesize (file)
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>
URL support was added in PHP 4.0.5
http://fr.php.net/manual/en/function.getimagesize.php
- silverbeach
- WRInaute occasionnel

- Messages: 333
- Inscription: 20 Juil 2005
merci ca marche
j'avais deja utilisé cette fonction mais je l'avais oublié
Mais je ne comprend toujours pas pourquoi ca n'a pas marché avec l'autre facon : imagesx determine aussi la largeur
j'avais deja utilisé cette fonction mais je l'avais oublié
Mais je ne comprend toujours pas pourquoi ca n'a pas marché avec l'autre facon : imagesx determine aussi la largeur
-

yazerty - WRInaute passionné

- Messages: 1682
- Inscription: 19 Juin 2005
Apparemment imagesx est fait pour avoir la largeur d'une image suite à la création d'un image, non ?
Mais je suis crevé là, je dis peut-être une connerie...
imagesx() retourne la largeur de l'image référencée par image.
Exemple 1. Exemple avec imagesx()
- Code: Tout sélectionner
<?php
// Création d'une image 300*200 image
$img = imagecreatetruecolor(300, 200);
echo imagesx($img); // 300
?>
Mais je suis crevé là, je dis peut-être une connerie...
5 messages
• Page 1 sur 1
Lectures recommandées sur ce thème :
- Vous préférez un site sur 100% de largeur ou largeur fixe ?
- Largeur de 1200px
- largeur de site conseillée
- largeur d'un champs
- probleme largeur de div
- largeur de ces sites, comment la trouver?
- Déclarer une largeur de site en em ?
- Largeur max d'une page...
- Background différent en fonction de la largeur du body
- Un fond de largeur 100% en CSS
- Astuces de référencement pour Google News - 08-04-2008
- La terre vue par satellite : accord entre Google et Spot Image - 23-01-2007
- Tutoriel sur le sitemap Google pour les images - 12-04-2010
- Ajouter un moteur de recherche d'images sur son site - 24-07-2007
- Idées d'optimisation du référencement des images - 19-09-2008
- Google change de favicon - 07-06-2008
- Nouveautés sur les recherches de Google Images - 22-02-2009
- Mise à jour de Google Images (16/04/2006) - 18-04-2006
Consultez la description détaillée des produits ou services de Google suivants : Google Image Labeler
Qui est en ligne
Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 0 invités


