avoir la largeur d'une image

silverbeach
WRInaute occasionnel
WRInaute occasionnel
 
Messages: 333
Inscription: 20 Juil 2005

avoir la largeur d'une image

Message le Sam Fév 18, 2006 20:41

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 :
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
WRInaute occasionnel
 
Messages: 284
Inscription: 13 Juil 2004

Message le Sam Fév 18, 2006 20:46

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

silverbeach
WRInaute occasionnel
WRInaute occasionnel
 
Messages: 333
Inscription: 20 Juil 2005

Message le Sam Fév 18, 2006 20:56

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 :?:


yazerty
WRInaute passionné
WRInaute passionné
 
Messages: 1682
Inscription: 19 Juin 2005

Message le Sam Fév 18, 2006 21:35

Apparemment imagesx est fait pour avoir la largeur d'une image suite à la création d'un image, non ?

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...


TOMHTML
WRInaute accro
WRInaute accro
 
Messages: 3250
Inscription: 25 Aoû 2004

Message le Sam Fév 18, 2006 22:02

non non yazery, t'as pas dit de conneries : tu as raison !

pour contrôler avant l'envoi, il faut passer par le javascript ;)


Si vous avez aimé cette discussion, partagez-la sur vos réseaux sociaux préférés :

Lectures recommandées sur ce thème :



Qui est en ligne

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