News:

Click here for Toll-Free Service for your business starting at $2.00 per month

Main Menu

Creating a standard Image size?????

Started by sixthcrusifix, January 18, 2006, 03:49:27 PM

Previous topic - Next topic

sixthcrusifix

I have a script that allows people to upload images to my site and I was wondering these things:

1. How can I make sure that the image is no bigger than 700x625 px in size (Filesize I don't care about)

2. How can I make sure they can only upload png, gif, jpeg, and jpg? (I knew this but I forgot :P)

3. Can I make a standard image size, as in EVERY image is stuck on a 700x625 px gray canvas so that pictures that are smaller than 700x625 px will end up being that size (centered hopefully) I'm doing this so that the tables will look proper and the small images won't make stuff look screwy.

4. LASTLY, and most importantly, if I can make every image go onto a 700x625 canvas (As in they'll be that size without scewing teh user's original) Is there an easy way I could add a black bar at the bottom with writting (variables that have teh username etc. )



OKAY, I managed to solve questions 3 and 4 on my own using this:


################################################
$conn = mysql_connect("localhost","sixthcrusifix","********");
$db = mysql_select_db("sixthcrusifix_DATA");
#$sql="select * from usergallery where username='$user_name' and password='$password'";
$user_name=$_COOKIE['user'];
$password=$_COOKIE['Password'];
$date=date("n-j-Y");#$date .= " "; $date .=date("g:i a");
if(isset($_POST['publish'])){$agree="YES";}else{$agree="NO";}
if(!isset($_POST['keywords'])){$keywords="none";}else{$keywords=$_POST['keywords'];}
$sql = "insert into usergallery (username,password,imagename,date,publish,keywords) values (\"$user_name\",\"$password\",\"$file_name\",\"$date\",\"$agree\",\"$keywords\")";
mysql_query($sql,$conn) ;

################################################
$flag = imagecreatefromjpeg("/fpgs/fpgshttpd/sixthcrusifix/MAIN/Gallery/images/gray.JPG");
$mask = imagecreatefromjpeg("/fpgs/fpgshttpd/sixthcrusifix/MAIN/Gallery/images/$file_name");
$mask_size = getimagesize("/fpgs/fpgshttpd/sixthcrusifix/MAIN/Gallery/images/$file_name");
$flag_size = getimagesize("/fpgs/fpgshttpd/sixthcrusifix/MAIN/Gallery/images/gray.JPG");

$center_x = .5*($flag_size[0]-$mask_size[0]);
$center_y = .5*($flag_size[1]-$mask_size[1]);

imagecopy($flag, $mask, $center_x,$center_y,0,0,$mask_size[0],$mask_size[1]);

imagejpeg($flag,"$MD$file_name");
##/////////////////////////////////////////////////////////
$string = "This is sooo cool it works!!!";                                             
$font  = 4;
$width  = ImageFontWidth($font)* strlen($string) ;
$height = ImageFontHeight($font) ;

$im = ImageCreateFromjpeg("$MD$file_name");
$x=imagesx($im)-$width ;
$y=imagesy($im)-$height;
#$background_color = imagecolorallocate ($im, 0, 0, 0); //white background

$text_color = imagecolorallocate ($im, 255, 255,255);//black text

imagestring ($im, $font, $x, $y,  $string, $text_color);
imagejpeg($im,"$MD$file_name");


HOWEVER My text doesn't have a background color :( ????



And teh first 2 questions still stand.
Visite me website at http://www.sixthcrusifix.com

x

for 1. and 2. use getimagesize. (www.php.net/getimagesize) have them upload the file, do the check, if it's too big or if it's not got the right type, delete it.

but if they upload a massive photo, you could just have the script resize the photo and crop it a bit

sixthcrusifix

Quote from: x on January 18, 2006, 09:53:03 PM
for 1. and 2. use getimagesize. (www.php.net/getimagesize) have them upload the file, do the check, if it's too big or if it's not got the right type, delete it.

but if they upload a massive photo, you could just have the script resize the photo and crop it a bit

oooh I see cool. But what about image type? should I just use preg_match in teh filename?
Visite me website at http://www.sixthcrusifix.com

GP™

Not sure if this is the best option out there, but you could use "mime_content_type".
It would return, for example me.gif would return image/gif

For more info go to: http://us3.php.net/manual/en/function.mime-content-type.php

L8r,
Gordon

GP™

After searching "Image" in php.nets database, I found this feature that may be more useful than my last post:
http://us2.php.net/manual/en/function.image-type-to-extension.php

This is a list of all php Image/GD features, you can go through them your self also, perhaps theres another method that is
best for your site, for example resize the image instead of blocking it all together!
http://us2.php.net/gd

Also, I recomend reading the user comments, they are VERY Useful!

L8r,
Gordon

x

Quote from: sixthcrusifix on January 18, 2006, 11:01:42 PM
Quote from: x on January 18, 2006, 09:53:03 PM
for 1. and 2. use getimagesize. (www.php.net/getimagesize) have them upload the file, do the check, if it's too big or if it's not got the right type, delete it.

but if they upload a massive photo, you could just have the script resize the photo and crop it a bit

oooh I see cool. But what about image type? should I just use preg_match in teh filename?

it's on that page as well. the function returns $width, $height, $type, $attr

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

so you just do a wee if statement and check for the number above