PHP - Creating Thumnails With Gd
Can anyone guide me on how to create thumbnails with php/gd. I'm trying to use gd to create thumbnails and then store in in my server. I'm currently using a function in my script, but some thumbnails come out black.
Here's part of the code: if (($extension == "jpeg") || ($extension == "jpg")) $originalImage = ImageCreateFromJPEG($sourceImagePath); elseif ($extension == "gif") $originalImage = ImageCreateFromGIF($sourceImagePath); elseif ($extension == "png") $originalImage = ImageCreateFromPNG($sourceImagePath); elseif($extension == "bmp") $originalImage = ImageCreateFromWBMP($sourceImagePath); // removed since Windows BMP is not supported $newImage = ImageCreateTrueColor($new_x, $new_y); ImageCopyResampled($newImage, $originalImage, 0, 0, $srcx, $srcy, $new_x, $new_y, $srcw, $srch); ImageJPEG($newImage, $imagePath, $outputImageQuality); ImageDestroy($newImage); ImageDestroy($originalImage); Similar TutorialsHello everyone, I found a tutorial on creating a pdf with php and I just tried to create a basic pdf to see if it worked and modify it from there. Here is the link to the tutorial: http://www.astahost.com/info/tfclt-create-pdf-php-create-fly-pdf-web-server.html Well, after uploading the following php file to the server and testing it, I got this error: Fatal error: Call to undefined function pdf_new() in /home/caresa6/public_html/BubblyBounce.com/admin/pdftest.php on line 2 Here's the code that produced the error: Code: [Select] <?php $mypdf = PDF_new(); PDF_open_file($mypdf, ""); PDF_begin_page($mypdf, 595, 842); $myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0); PDF_setfont($mypdf, $myfont, 10); PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750); PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730); PDF_end_page($mypdf); PDF_close($mypdf); $mybuf = PDF_get_buffer($mypdf); $mylen = strlen($mybuf); header("Content-type: application/pdf"); header("Content-Length: $mylen"); header("Content-Disposition: inline; filename=gen01.pdf"); print $mybuf; PDF_delete($mypdf); ?> Can anyone help me figure out what to do from here? I have some PHP knowledge, but I'm treading in uncharted waters with this, so I am totally lost. Thanks in advance. i need to create a to do list with php. but i dont want to use database .is there anything else i can use instead of using a database? i need to delete ,add functions .how may i do this? basicly it will have process.php,index.php and delete.php it may need more pages though. im a beginner so , code shouldnt be complicated and should be with explanation please . thanks. I am in the process of creating a like system for a personal website that I am working on. I am trying to pull information from one database and use that to place info into another database. When I do I get resource error #15. This is my code that I have so far Code: [Select] function like_add() { $last = $_GET['l']; $first = $_GET['f']; $ip = $_SERVER['REMOTE_ADDR']; $like_sql = "Select * from `counter` where first = ' $first ' and last = '$last '"; $like_result = mysql_query($like_sql); $likes = '<p class="like_button"> Likes '; while ($like_row = mysql_fetch_assoc($like_result)) { $like = $like_row['likes']; $likes .= " $like"; } $likes .= '</p>'; echo "$likes"; echo '<form name="like_add_form" action="" method="POST" class="like_add"> <input type="submit" name="like_add" class="like_add_button" value="Like Me" /> </form>'; if (isset($_POST['like_add'])) { $page_id = "SELECT `page_id` FROM `counter` WHERE first = '$first' AND last = '$last'"; $page_id_result = mysql_query($page_id); echo $page_id_result; <----- Here I am trying to pull information from a field in my database to use as a variable and to place in the second database $voted = mysql_query("Select * FROM `liked_ip` where ip ='$ip' AND page_id='$page_id_result'"); <----- Here I want to use the information from the first table to place in the second one if (mysql_num_rows($voted) != 0) { echo "You have all ready liked this post"; } else { mysql_query("INSERT into `liked_ip`(id,page_id,ip) VALUES ('$page_id_result','$ip')"); } if (mysql_num_rows($voted) == 0) { mysql_query("UPDATE counter SET `likes` = `likes` + 1 where first = '$first' AND last = '$last'"); } } } I know that I have to be doing something so simple that I am just not seeing it this late at night. I may even be completely wrong in all of this. If someone could please help me out I would appreciate it very much. Hello! First I would like to say welcome to the forums! I hope one day I'll be able to give back!! Anyway, I seem to not know how to do this. I'm creating a website for my guild, and I'm very very rusty with PHP (learned it a year or two back than lost it). Anyway, I made the script to display the calendar portion of it (followed a tutorial), but I can't seem to import the feature to display events in the same cell as the date that its on. Sorry my coding is a little sloppy but I'm hoping you guys can help xD I left off with thinking that maybe i could use an array to do the job but I honestly have no clue how to go about this... Code: [Select] <?php function calendar(){ include('connect.php'); $month = date("n"); $year = date("Y"); $query = "SELECT * FROM calendar WHERE (month='$month' AND year='$year')"; $result = mysql_query($query); $num = mysql_num_rows($result); $firstDay1 = mktime(0,1,0,$month,1,$year); $firstDay = mktime(0,1,0,$month,1,$year); $daysInMonth = date("t",$firstDay); $firstDay = date("w",$firstDay); $day1 = array(); $message = array(); $message1 = ''; $dayNumber = 1; $i = 0; while ($i < $num) { $day1[$i] = mysql_result($result,$i,"day"); $message[$i] = mysql_result($result,$i,"message"); $i++; } echo "<table width='280' border='1'>\n"; echo "<tr>\n"; echo "<td align='center'>" . date("F Y") . "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td>\n"; echo "<table width='490' border='0' cellspacing='2' cellpadding='2'>\n"; echo "<tr align='center'>\n"; echo "<td width='70'>Sun</td>\n"; echo "<td width='70'>Mon</td>\n"; echo "<td width='70'>Tue</td>\n"; echo "<td width='70'>Wed</td>\n"; echo "<td width='70'>Thu</td>\n"; echo "<td width='70'>Fri</td>\n"; echo "<td width='70'>Sat</td>\n"; echo "</tr>\n"; # Calculate number of rows $totalCells = $firstDay + $daysInMonth; if($totalCells < 36){ $rowNumber = 5; } else { $rowNumber = 6; } # Create Rows for($currentRow=1; $currentRow <= $rowNumber; $currentRow++){ if($currentRow == 1){ # Create First Row echo "<tr align='center'>\n"; for($currentCell = 0; $currentCell<7; $currentCell++){ if($currentCell == $firstDay){ # First Day of the Month if($day1 == $dayNumber){ $message1 = $message; } else { $message1 = ""; } echo "<td width='70' height='50'>" . $dayNumber . "<br />$message1</td>\n"; $dayNumber++; } else { if($dayNumber > 1){ # First Day Passed so output Date if($day1 == $dayNumber){ $message1 = $message; } else { //$message1 = ""; } echo "<td width='70' height='50'>" . $dayNumber . "<br />$message1</td>\n"; $dayNumber++; } else { # First Day Not Reached so display blank cell echo "<td width='70' height='50'> </td>\n"; } } } echo "</tr>\n"; } else { # Create Remaining Rows echo "<tr align='center'>\n"; for($currentCell = 0; $currentCell < 7; $currentCell++){ if($dayNumber > $daysInMonth){ # Days in month exceeded so display blank cell echo "<td width='70' height='50'> </td>\n"; } else { if($day1 == $dayNumber){ $message1 = $message; } else { $message1 = ""; } echo "<td width='70' height='50'>" . $dayNumber . "<br />$message1</td>\n"; $dayNumber++; } } echo "</tr>\n"; } } echo "</table>\n"; echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; } calendar(); ?> Thank you guys so much!!! It will mean alot to me and my guild xD!! **EDIT** Forgot to add, Database looks like this id day month year message Thanks again! hey guys, im new to all this php stuff. I have a project in this semester to create an HR contract system for the university, here are my requirements: 1. Add Contracts 2. Delete Contracts 3. Edit Contracts 4. View Contracts 5. Search Contracts i have done all the 4 options but now im stuck in the 5th option. i have to use checkboxes filters for search and first and the last name fields. here is my form code <form method="post" action="searchCode.php"> First Name: <input name="name" type="text" id="name" /> Middle Name: <input name="mname" id="mname" type="text" /> Last Name: <input name="lname" id="lname" type="text" /> Date: <input type="text" name="date" id="currentdate" /> <input type="checkbox" name="gender[]" value="male" />Male<br /> <input type="checkbox" name="gender[]" value="female" />Female <input name="desig[]" type="checkbox" value="lecturar"/>Lecturar <input type="checkbox" name="desig[]" value="professor" />Professor <input type="checkbox" name="desig[]" value="assistantProfessor" />Assistant Professor <input type="checkbox" name="desig[]" value="associateProfessor" />Associate Professor <input type="checkbox" name="desig[]" value="researchAssociate" />Research Associate<br /> <input type="checkbox" name="desig[]" value="advisor" />Advisor <input type="checkbox" name="desig[]" value="HOD" </span> <input name="dept[]" type="checkbox" value="Comuter Science" />Computer Science <input type="checkbox" name="dept[]" value="Health Informatics Unit" />Health Informatics Unit <input name="dept[]" type="checkbox" value="Electrical Engineering" />Electrical Engineering <input type="checkbox" name="dept[]" value="Management Sciences" />Management Sciences<br /> <input type="checkbox" name="dept[]" value="Mathamatics" />Mathamatics <input type="checkbox" name="dept[]" value="Physics" />Physics <input type="checkbox" name="dept[]" value="Bio Sciences" />Bio Sciences <input type="checkbox" name="dept[]" value="Meteorology" />Meteorology <input type="checkbox" name="dept[]" value="Architecture" />Architecture <input name="scales[]" type="checkbox" value="sg1" />SG-I <input name="scales[]" type="checkbox" value="sg2" />SG-II <input name="scales[]" type="checkbox" value="sg3" />SG-III <input name="scales[]" type="checkbox" value="sg4" />SG-IV <input name="scales[]" type="checkbox" value="ras" />RA <input name="scales[]" type="checkbox" value="og1nphd" />OG-I- <input name="scales[]" type="checkbox" value="og2nphd" />OG-II-NonPhd <input name="scales[]" type="checkbox" value="og3nphd" />OG-III-NonPhd <input name="scales[]" type="checkbox" value="og4nphd" />OG-IV-NonPhd <input name="scales[]" type="checkbox" value="og2phd" />OG-II-Phd <input name="scales[]" type="checkbox" value="og3phd" />OG-III-Phd <input name="scales[]" type="checkbox" value="og4phd" />OG-IV-Phd</p> now i cant seem to get it in my mind tht how the hell im going to do tht...shud i use ifs and elses, in tht case it can get upto 256 combinations. and 1 more thing all these things are in one table....please gyus help me Hi, I am trying to create a cron job that truncates a database table, then inserts data back into the table, The cron jobs works fine, if i just truncate the table, but does not seem to work if i want to re-insert data back in the table. truncate.php looks as follows: <?php require_once('/usr/www/users/amisea/sosams/db-connecter.php'); $query = "TRUNCATE TABLE tmpsessionmodule; INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module1 FROM session WHERE ((Module1) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module2 FROM session WHERE ((Module2) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module3 FROM session WHERE ((Module3) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module4 FROM session WHERE ((Module4) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module5 FROM session WHERE ((Module5) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module6 FROM session WHERE ((Module6) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module7 FROM session WHERE ((Module7) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module8 FROM session WHERE ((Module8) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module9 FROM session WHERE ((Module9) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module10 FROM session WHERE ((Module10) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module11 FROM session WHERE ((Module11) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module12 FROM session WHERE ((Module12) <>"" );" $result = @mysql_query($query); ?> Code: [Select] SELECT * FROM table1,table2,table3,table4,table5 WHERE table1_f = table2_id AND table1_g = table3_id AND table4_p = table1_id AND table5 _m = table4_id ORDER BY RAND() LIMIT 1 Right, Now What I want to do, is have a filter form, which posts to the above, and if: $filter1 = ""; it wont be include in the above code $filter1 = "word"; then i want to include AND table3_n = '$filter1'; in the above code thanks in advance. Hello all I have a requirement to create images mostly made up of rectangles circles and squares etc I have discovered imageline but is there anything a bit more exspansive? I have set up a database using myPHPadmin, I have created the following code: Code: [Select] <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("127.0.0.1","root","password") or die("Couldnt connect to database"); mysql_select_db("login") or die ("Couldnt find database"); $query = mysql_query("SELECT * FROM users WHERE username ='$username'"); $numrows = mysql_num_rows ($query); if($rumrows != 0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&$password==$dbpassword) { echo "Login successful. <a href='members.php'> Click here to enter memebers area </a>"; $_SESSION['username']=$dbusername; } else echo "Incorrect password"; } else die ("Username does not exist"); } else die ("Please enter a username and password"); ?> Even though the database is set up when i try and enter the username for the log in page and password, it says the username does not exist? I dont understand why when it is in the database? Please help! MOD EDIT: [code] . . . [/code] BBCode tags added. hi i open this post so i dont open 5 new ones ok i have a task to do an event calendar now i found some tutorial for creating simple calendar BUT all of them are on english what i need is change it to croatian - that means i have custom names for days, custom names for months, and what i also need is put sunday where it belongs... at the end because we are calculating week starts by monday... so any tips? if you know some tutorial that works for these spec things i googled it but i only found like 2 calendars that actualy works other have some bugs in scripts and wont do thing or just write me tips and ill try to create it I want to create an image using pre-existing image files. I want to use more than one file, otherwise I would use the imagecreatefromjpg function. What function should I use to create an image using a for statement to determine how many of each image is being displayed in the new image? I am trying to create random no. of directories but its always giving this error Warning: mkdir() [function.mkdir]: Invalid argument in C:\xampp\htdocs\gl\movie_process.php on line 173 the code is for(i=0; i<5; i++) { mkdir("".$base."uploads/movies/$year/$month/$title/".$hosting[$i].""); } I want to add some text onto an image. Sometimes I either get nothing returned or I get a shit load of garbage returned. Garbage in the form of little question mark symbols and other crap like that. PHP File - show Tickets Code: [Select] include("createImage.php"); while( $row = mysql_fetch_array( $r ) ){ echo generateTicket( $row['ticketNumber'] ) . "<br /><br />"; } PHP - createImage.php Code: [Select] <? header("Content-type: image/jpeg"); function generateTicket( $ticketNum ){ $imageFile = "images/ticket.jpeg"; if( file_exists( $imageFile ) ){ $im = @imagecreatefromjpg( $imageFile ); $text_color = imagecolorallocate( $im, 0, 0, 0 ); imagestring( $im, 6, 25, 150, $ticketNum, $text_color ); imagejpeg( $im ); }else echo 'error'; } ?> I want to create a REST API for my website. What I want to do is to display advertisements from my database on websites that I sell to clients. Their website will call my database for advertisements to display on their websites. Also, I am performing a site validity check where the client's site would send the site URL, site name, and site token to my database for validation. If it returns false then the site will not display as it will be invalid according to my database. I've been Googling this topic all day, but cannot seem to get my head around it. I want to set an API key on my website so that not just anybody can be querying my database. For the advertisement query, no parameters need to be sent from the client websites to my database. Can anyone offer some advice on how to do this? Hi, I have a small piece of code that creates an RSS feed using a mysql database. The issue is the page itself is blank however if I right click and view source I can see all the feed there. I convert the dat time field into a standard RSS date field. The web address is http://vinovote.com/news/feed.php My code is as follows Code: [Select] <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> <rss version="2.0"> <channel> <title>Vinovote.com</title> <description>The Latest News And Views From Around The Web</description> <link>http://www.vinovote.com/</link> <copyright>Your copyright information</copyright> <?php require_once('../Connections/connection.php'); mysql_select_db($database_vinovotedb, $vinovotedb); $doGet = mysql_query("SELECT feed_content.feed_content_id, feed_content.feed_id, feed_content.url, feed_content.title, feed_content.content, feed_content.item_time, Date_FORMAT(feed_content.item_time,'%a, %d %b %Y %T') AS pubDate FROM feed_content order by item_time desc LIMIT 50 ", $vinovotedb) or die(mysql_error()); while($result = mysql_fetch_array($doGet)){ ?> <item> <title> <?php echo $result['title']; ?></title> <description> <?php echo $result['content'];?></description> <link><?php echo $result['url'];?></link> <pubDate> <?php echo $result['pubDate']; ?></pubDate> </item> <?php } ?> </channel> </rss> I need help making the variable $code in sessions.php to work with the email activation. sessions.php Code: [Select] <?php include(MODEL_PATH.'user.php'); switch ($route['view']){ case "register": break; case "signup": $errors = validate($register_validations, $params['register']); if($errors) { //$route['view'] = 'index'; $route['view'] = 'register'; //print_r($errors); flash_warning('Please correct errors!'); } else { $code = I need this variable to included the random number created in user.php so it can be sent in the email; $register = $params['register']; $username = $register['screen_name']; $to = $register['user_email']; $subject = "Activate your account"; $headers = "From: richard@whatsyouraction.com"; $body = "Hello $username,\n\nYou registered and need to activate your account by clicking the link below\n\nhttp://whatsyouraction.com/chatbox/emailactivation/activate?code=$code\n\nThanks!"; if (!mail($to,$subject,$body,$headers)) { flash_warning('We couldn\'t sign you up at this time. Please try again later.'); $route['view'] = 'register'; } else { create_user($params['user']); flash_notice('Successfully registered!'); redirect_to('sessions/login'); } } break; } ?>user.php Code: [Select] <?php function create_user($params) { db_connect_posts(); $code = rand(11111111,99999999); $query = sprintf("INSERT INTO users SET users.screen_name = '%s', users.user_email = '%s', users.user_pwd = '%s', users.image = '%s', created_at = NOW(), users.code = $code, users.active = '0'" , mysql_real_escape_string($params['screen_name']), mysql_real_escape_string($params['user_email']), md5($params['user_pwd']), mysql_real_escape_string($params['image']) ); $result = mysql_query($query); if(!$result) { return false; } else { return true; } } ?>register.php Code: [Select] <form action="<?php echo '/'.APP_ROOT.'/'; ?>sessions/signup" method="post"> <fieldset> <legend>Register</legend> <div> <label>Screen Name</label> <input name="register[screen_name]" size="40" type="text" /> </div> <div> <label>E-mail</label> <input name="register[user_email]" size="40" type="text" /> </div> <div> <label>Password</label> <input name="register[user_pwd]" size="40" type="password" /> </div> <div> <label>Image</label> <input name="register[image]" size="40" type="text" /> </div> <input type="submit" name="submit" value="Register" /> </fieldset> </form> I am trying to create a madlibs game .. I have a txt file with paragraphs in it .. Some of the sentences have the following tags in it <#noun>, or <#verb>, etc ... I need to parse the file in php and display the content in between the tags to the user. The user can fill the the words in text box, and the story will be displayed with the new words instead of the tags. I am new to php. Any help greatly appreciated. Thanks in Advance, Vladimir Is there a way to use PHP to edit html without having to store it in my DB? For example I would like someone to be able to edit a paragraph on the page, its wrapped in a <div class="editable"> now is there a way to have PHP detect that div and have an textarea to edit it directly without having to store anything in a DB? I hope that makes sense if it doesn't let me know! Thanks i am able to create csv's and can do so with no trouble .. but what i am having difficulty with is being able to auto save the csv and then email it all in one script. anybody every dealt with something like this? |