Have an account? Sign in
Login  Register  Facebook
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.
Started: September 22, 2011 Latest Activity: September 22, 2011 getimagesize
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
In: September 22, 2011

This can judge the image size before insert into the database. Thanks friends.
September 22, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer