Save the above file as SimpleImage.php and take a look at the following examples of how to use the script.
The first example below will load a file named picture.jpg resize it to 250 pixels wide and 400 pixels high and resave it as picture2.jpg
include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resize(250,400);
$image->save('picture2.jpg');
?>
If you want to resize to a specifed width but keep the dimensions ratio the same then the script can work out the required height for you, just use the resizeToWidth function.
include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(250);
$image->save('picture2.jpg');
?>
You may wish to scale an image to a specified percentage like the following which will resize the image to 50% of its original width and height
include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->scale(50);
$image->save('picture2.jpg');
?>
You can of course do more than one thing at once. The following example will create two new images with heights of 200 pixels and 500 pixels
include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToHeight(500);
$image->save('picture2.jpg');
$image->resizeToHeight(200);
$image->save('picture3.jpg');
?>
The output function lets you output the image straight to the browser without having to save the file. Its useful for on the fly thumbnail generation
header('Content-Type: image/jpeg');
include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(150);
$image->output();
?>
The following example will resize and save an image which has been uploaded via a form
This is really quite simple. All you need to do is download Connector/Net which is a fully-managed ADO.NET driver written in 100% pure C#. Download the installer and install Connector/Net. After installation load your C# IDE. Begin a new console project.
The first thing you need to do is add a reference to your project. Open the Add Reference dialog box. Under the .Net tab scroll down to MySQL.Data and add this reference to your project. Before we start with the actual code we need to add two namespaces. Add the following namespaces.
using MySql.Data.MySqlClient; using MySql.Data.Types;
Finally now time to write some code. When connecting to any database you usually need to set up a provider. This provder is of type string and simply consists of information such as database to connect to, username, password and url/name of the machine in which the database is hosted. This provider sring is different for different databases. The provider string needed to connect to a MySQL database is listed below.
In the provider string above we simply supply the data source, which is the url/ip/name of the computer which the database is hosted on. We also supply the database name to connected to and the username and password.
If your using a default MySQL installation, the username should be and the password should be the password you used in the installation process.
After setting up a provider, you need to create a connection to the database. You do this by using the MySqlConnection object.
When creating an instance of MySqlConnection, you supply the provider in it’s constructor.
Now that the connection is open, you need to query the database. You need to send an SQL statement to get the results from the database. This is done using the MySqlCommand object. In the constructor of the MySqlCommand you supply an SQL statement and also the connection object.
Now the MySqlDataReader object will contain all the records from the database. The MySqlDataReader object is a read only onject, which allows you to quickly get records out of a database table. It can not be used to update a database table.
To get records from the MySqlDataReader object you use a while loop. The loop uses the MySqlDataReader objects Read() method, to get the data for each row.
Finally you use the appropriate methods of the MySqlDataReader object to get the data from each column. For example the first column is returned as an Integer using the GetInt32() method, while the second and third columns return string data.
The Microsoft .NET framework provides two namespaces, System.Net and System.Net.Sockets for managed implementation of Internet protocols that applications can use to send or receive data over the Internet . SMTP protocol is using for sending email from C#. SMTP stands for Simple Mail Transfer Protocol . C# using System.Net.Mail namespace for sending email . We can instantiate SmtpClient class and assign the Host and Port . The default port using SMTP is 25 , but it may vary different Mail Servers .
The following C# source code shows how to send an email from a Gmail address using SMTP server. The Gmail SMTP server name is smtp.gmail.com and the port using send mail is 587 and also using NetworkCredential for password based authentication.
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
SmtpServer.Port = 587;
SmtpServer.Credentials =
new System.Net.NetworkCredential("username", "password");
We give the link an ID - in this case, "emailUs" - which allows us to style the link via our CSS. We also place the actual link text inside a span element. This means that we can hide the link text with our CSS and display the image instead, yet the link still looks like a regular text link to browsers not using the style sheet - such as a search engine spider or a text-only browser, for example.
/// /// Gets IP addresses of the local computer /// public string GetLocalIP() { string _IP = null;
// Resolves a host name or IP address to an IPHostEntry instance. // IPHostEntry - Provides a container class for Internet host address information. System.Net.IPHostEntry _IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
// IPAddress class contains the address of a computer on an IP network. foreach (System.Net.IPAddress _IPAddress in _IPHostEntry.AddressList) { // InterNetwork indicates that an IP version 4 address is expected // when a Socket connects to an endpoint if (_IPAddress.AddressFamily.ToString() == "InterNetwork") { _IP = _IPAddress.ToString(); } } return _IP; }
Calculating Date Difference in C Sharp Code Sample: Calculating the Date Difference - Subtract Method. using System; using System.Collections.Generic; using System.Text;
namespace Console_DateTime { class Program { static void Main(string[] args) { System.DateTime dtTodayNoon = new System.DateTime(2006, 9, 13, 12, 0, 0); System.DateTime dtTodayMidnight = new System.DateTime(2006, 9, 13, 0, 0, 0); System.TimeSpan diffResult = dtTodayNoon.Subtract(dtYestMidnight); Console.WriteLine("Yesterday Midnight - Today Noon = " + diffResult.Days); Console.WriteLine("Yesterday Midnight - Today Noon = " + diffResult.TotalDays); Console.ReadLine(); } } } Back Main
// Define message Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Hello JavaMail Attachment"); // Create the message part BodyPart messageBodyPart = new MimeBodyPart(); // Fill the message messageBodyPart.setText("Here's the file"); // Create a Multipart Multipart multipart = new MimeMultipart(); // Add part one multipart.addBodyPart(messageBodyPart); // // Part two is attachment // // Create second body part messageBodyPart = new MimeBodyPart(); // Get the attachment DataSource source = new FileDataSource(filename); // Set the data handler to the attachment messageBodyPart.setDataHandler(new DataHandler(source)); // Set the filename messageBodyPart.setFileName(filename); // Add part two multipart.addBodyPart(messageBodyPart); // Put parts in message message.setContent(multipart); // Send the message Transport.send(message); } }
URLName urln = new URLName("pop3","pop.gmail.com",995,null, "USERNAME", "PASSWORD"); Store store = session.getStore(urln); Folder inbox = null; try{ store.connect(); inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_ONLY); FetchProfile profile = new FetchProfile(); profile.add(FetchProfile.Item.ENVELOPE); Message[] messages = inbox.getMessages(); inbox.fetch(messages, profile); System.out.println("Inbox Number of Message" + messages.length); for (int i = 0; i < style="color:navy;">{
String from = decodeText(messages[i].getFrom()[0].toString()); InternetAddress ia = new InternetAddress(from);System.out.println("FROM:" + ia.getPersonal()+'('+ia.getAddress()+')');