How to determine the picture size, then selectively insert into the database?
I have 5 pictures, img1.jpg, img2.png, img3.gif, img4.jpg, img5.png. how to determine the picture size, if it is a Horizontal picture( width is more than height)width>=300px and height>=200, then insert into the database? else the pisture is a Vertical picture or width less than 300px and height less than 200px, refuse insert it into the database?
<?php $links = array("img1.jpg", "img2.png", "img3.gif", "img4.jpg", "img5.png"); $sizearray = array(); $count = count($links); for($i = 0; $i < $count; $i++) { $size = getimagesize($links[$i]); list($width, $height) = $size; $sizearray[$links[$i]] = array("width" => $width, "height" => $height); } print_r($sizearray); // which will print out: Array ( [img1.jpg] => Array ( [width] => 300 [height] => 400 ) [img2.png] => Array ( [width] => 680 [height] => 330 ) [img3.gif] => Array ( [width] => 50 [height] => 50 )[img4.jpg] => Array ( [width] => 400 [height] => 250 )[img5.png] => Array ( [width] => 400 [height] => 300 )) ?> <?php mysql_query("INSERT INTO photo (id,image) VALUES ('', '".$links."')"); ?> This should insert img2.png and img5.png into the database. Thanks.
1 Answer
for($i = 0; $i < $count; $i++) { $size = getimagesize($links[$i]); list($width, $height) = $size; if ($width > $height && $width >= 300 && $heigth>=200) mysql_query(\"INSERT INTO photo(image) VALUES(\'\".$links[$i].\"\')\"); }try that Posted: MacOS 2 of 2 people found this answer helpful. Did you? Yes No This can judge the image size before insert into the database. Thanks friends. |
© Advanced Web Core. All rights reserved