Posts Tagged ‘Technology’
Resize a picture to a fixed size
This function creates a thumbnail that is exactly as big as the size you give it. The image is resized to best fit the size of the thumbnail. If it does not fit exactly in both directions, it’s centered in the thumnail.
The Function:
function thumbnail_box($img, $box_w, $box_h) {
//create the image, of the required size
$new = imagecreatetruecolor($box_w, $box_h);
if($new === false) {
//creation failed -- probably not enough memory
return null;
}
//Fill the image with a light grey color
//(this will be visible in the padding around the image,
//if the aspect ratios of the image and the thumbnail do not match)
//Replace this with any color you want, or comment it out for black.
//I used grey for testing =)
$fill = imagecolorallocate($new, 200, 200, 205);
imagefill($new, 0, 0, $fill);
//compute resize ratio
$hratio = $box_h / imagesy($img);
$wratio = $box_w / imagesx($img);
$ratio = min($hratio, $wratio);
//if the source is smaller than the thumbnail size,
//don't resize -- add a margin instead
//(that is, dont magnify images)
if($ratio > 1.0)
$ratio = 1.0;
//compute sizes
$sy = floor(imagesy($img) * $ratio);
$sx = floor(imagesx($img) * $ratio);
//compute margins
//Using these margins centers the image in the thumbnail.
//If you always want the image to the top left,
//set both of these to 0
$m_y = floor(($box_h - $sy) / 2);
$m_x = floor(($box_w - $sx) / 2);
//Copy the image data, and resample
//If you want a fast and ugly thumbnail,
//replace imagecopyresampled with imagecopyresized
if(!imagecopyresampled($new, $img, $m_x, $m_y, 0, 0, $sx, $sy, imagesx($img), imagesy($img))) {
//copy failed
imagedestroy($new);
return null;
}
//copy successful
return $new;
}
Example Usage:
$i = imagecreatefromjpeg("img.jpg");
$thumb = thumbnail_box($i, 210, 150);
imagedestroy($i);
if(is_null($thumb)) {
/* image creation or copying failed */
header('HTTP/1.1 500 Internal Server Error');
exit();
}
header('Content-Type: image/jpeg');
imagejpeg($thumb);
Customizing the Calendar control in ASP.NET
Recently I had to work on customizing an ASP.NET Calendar control by adding text to the day cells for my team’s Logon Message project. This proved to be not as straight-forward as I thought so here is what I did in case someone else might want to do the same.
The best place to modify the text in a cell seems to be the DayRender event handler. So the first thing I tried was to just modify the e.Cell.Text property like this:
void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
e.Cell.Text += “My text”;
}
The main problem was that after adding text to a day cell in the control I wasn’t able to select that day by clicking on the day number. Here is what you can do if you still want the select day functionality:
void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
AddTextToDayCell(e, Datetime.Today, “MyText“);
}
void AddTextToDayCell(DayRenderEventArgs e, Datetime d, string text)
{
if(e.Day.Date == d.Date)
{
string ID = ((System.TimeSpan)(e.Day.Date - new DateTime(2000, 1, 1))).Days.ToString();
e.Cell.Text = "<a href=\"javascript:__doPostBack('Calendar1','" + ID + "')\" style=\"color:#663399\">" + e.Day.DayNumberText; //assuming the name of the calendar control is Calendar1.
e.Cell.Text +=text;
}
}
If you want your new text to act as a link to some other URL, you could modify the AddTextToCell function as follows:
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
AddTextToDayCell(e, DateTime.Today, "MyText", "<a href="http://fathir.com/">http://fathir.com</a>"); //this will add the MyText link to <a href="http://fathir.com/">http://fathir.com</a> to the current day's cell
}
void AddTextToDayCell(DayRenderEventArgs e, DateTime d, string text, string URL)
{
if(e.Day.Date == d.Date)
{
string ID = ((System.TimeSpan)(e.Day.Date - new DateTime(2000, 1, 1))).Days.ToString();
e.Cell.Text = "<a href=\"javascript:__doPostBack('Calendar1','" + ID + "')\" style=\"color:#663399\">" + e.Day.DayNumberText;
e.Cell.Text += "<br /> <a href=\""+ URL + "\">" + text;
}
}
Hope you’ll find this helpful.
Editing the Windows Registry
In this tutorial, I’m going to go through the code required to edit the Windows registry using C#. This will include creating new keys and values as well as modifying existing ones.
The registry is a great way to save information between application launches. Many applications use the registry to save information about dialog sizes and placements. That way the user doesn’t have to resize and move dialogs every time the program starts.
Let’s start by creating a new registry key. The first thing we need to decide is where to put our new key. If you bring up the Registry Editor – type “regedit” in the run bar, you’ll notice the registry looks a lot like a file explorer. “Computer” is the root node with several child folders branching from it.
Most software packages will have a registry key inside
HKEY_LOCAL_MACHINE->SOFTWARE
These keys are available no matter who is logged in and is a good place to stick general application values. Let’s put a key in this folder called “My Registry Key”.
Registry is a class located in the Microsoft.Win32 namespace. Registry.LocalMachine means where going to be modifying the HKEY_LOCAL_MACHINE registry key. We passed in “SOFTWARE\\My Registry Key” to CreateSubKey because we wanted our new key created inside the “SOFTWARE” key. CreateSubKey has the option to take more arguments – mostly dealing with access and security, but they’re not important for this tutorial.
If you open the Registry Editor again, you’ll now see you’re new key. A key without any values is pretty useless, so let’s add a string value to it.
myKey.SetValue(“My String Value”, “Test Value”, RegistryValueKind.String);
The OpenSubKey method is called to get a reference to our newly created key. It takes the path to the key, which is the same as when creating it, and it takes a boolean indicating whether or not we want to open it writable. Since we want to add a new value to this key, we want to set this to true.
Next, we simply call SetValue to create our new value. The SetValue function takes the name of the value as the first argument, the actual value as the second, and the type of value as the third. The RegistryValueKind enumeration has lots of different kinds of data, so most primitive types can be stored in the registry. If the value you’re trying to set doesn’t exist yet (like in this case), SetValue will create it for you.
Now let’s look at how to get values back out of the registry. It’s very similar to setting values and equally as easy.
string myValue = (string)myKey.GetValue(“My String Value”);
//myValue now equals “Test Value”
We get a reference to our key exactly like we did before except this time we pass false for the writable argument. A call to GetValue is then made to retrieve the value from the registry. This function returns an object, so it must first be cast to your desired type – in this case string. It’s always wise to check that the return value is not null before casting it since it is possible that the registry value you’re trying to read doesn’t exist.
How to Minimize an Application to the Taskbar Tray in C#
One very convenient features in windows is the Taskbar. To make it even better, those little icons can make something so “out of the way” that you can forget what is even down there. But, sometimes you want your applications to hang down there, out of the way, doing something that requires little attention. You can even make some notification bubbles show up if you want.
Today I am going to be using Visual Studio Express 2008, and luckily this makes things really easy. I am assuming that you know how to create a new project, so once you have one open, we can get started. I named my “HideTaskBar”, but as always, any name is fine.
This whole process revolves around an object named NotifyIcon. Like most .NET objects, this one is designed to make the job easier. With it we can give our application its very own cute icon in the taskbar, and notify our users of important information. Of course, to start you need to add the object to your form, so go ahead and do that. The object is a common control.
The NotifyIcon’s Properties
The first thing you absolutely must do is set the Icon property. This can be found in the properties window when you have the NotifyIcon object selected. If you don’t, nothing will show up in the taskbar tray.
Moving on to our code, the first thing we need to do is “hide” the form when we minimize it. To do this, we simply tie the action to the resize event. This is crude at best, but for this tutorial it gets the point across:
Hide();
As I stated above, this simple code goes in the resize event of the form. We are checking to see if the form is minimized, if it is, we hide it. It’s that simple. Now we have to setup an “un-minimize” event that will show our app when we double click the icon. If you take a look at the NotifyIcon object, you will notice a DoubleClick event. How convenient, huh?
What we have to do on the event is show the form, then set its WindowState to normal:
WindowState = FormWindowState.Normal;
Again, that simple. But, we can do a little more. How about adding a some notifications? Yeap, the NotifyIcon object can do that as well. Windows calls them bubbles, and you can access them through the object. Let’s go ahead and add one to notify us of the minimization of the app:
{
Hide();
notifyIcon1.BalloonTipTitle = “APP Hidden”;
notifyIcon1.BalloonTipText = “Your application has been minimized to the taskbar.”;
notifyIcon1.ShowBalloonTip(3000);
}
This will make a balloon tip pop up and notify us from the taskbar. As you can imagine the possibilities are pretty endless as far as the NotifyIcon object goes. You can use this pretty much anywhere, so any action can have a balloon tip. In fact, no one even said you have to use the notification icon for minimizing.
Now we know what is going on.
Make Transparent Effects in PowerPoint 2007
Sometimes we need a clip art image that appears transparent in our PowerPoint presentation. For example, as the background of a paragraph that mixed with the original background image.
To do the following steps:
- Click on the Insert ribbon tab and click the button on the Clip Art
- Click the Go button in the panel and select Clip Art Clip Art, and put in the presentation
- Make a right click on clip art and select Group -> Ungroup
- On the question “Do you want to convert …?” click Yes
- Do it again, right click on the clip art and select Group -> Ungroup
- In the clip art is still selected, open the Format ribbon click on the Shape Fill button and select More Fill Colors
- Select colors and transparency values that match your background and click the OK button
- If there is any area of the square with the clip art images, simply click on the area of a square and pressing the delete key
Installing and Using Add-in: Microsoft Save as PDF
How to install:
- Download file SaveAsPDF&XPS di www.microsoft.com link:
http://download.microsoft.com/download/b/5/3/b5370004-d59d-493f-b005-2299ffca8596/SaveAsPDF.exe - Then click 2 times on SaveAsPDF & XPS file in the folder where you save downloaded earlier
- License Agreement screen appears, click on “Click here to accept …” and click Continue
- Then wait until the installation is finished, and press OK
Then the steps to save the file to PDF from Microsoft Office 2007 are:
- Create a document with Microsoft Office or Microsoft Excel
- Once completed, click Home and then click continue to select Save As PDF or XPS
- Then you specify the file name and select the PDF file type. Click Publish. So your document in the form of PDF files.
How to open Firefox faster
Have you ever noticed on how fast IE loads compared to Firefox? That is because XP preloads IE on its start-up.
After some research i found that Firefox developers have chosen not to tie up system resources before they really need it, but if you want it to load fast it is possible to achieve that by doing the same thing as what IE does.
1. Put your Firefox shortcut onto you start menu. Easier way of doing this is if you have a shortcut on your desktop drag it onto you start button on your button left.
2. Right click on the shortcut in the start menu and then ‘Properties’. Find the target section which should contain something similar [ "C:\Program Files\Mozilla Firefox\firefox.exe" ] , add ‘/Prefetch:1′ next to the address (without the inverted commas). SO the target box should contain what is in the square brackets as follows [ "C:\Program Files\Mozilla Firefox\firefox.exe" /Prefetch:1 ]

Now by doing this Windows XP should preload Firefox on its start-up, so Firefox loads as fast as IE.
source : http://www.trap17.com/index.php/how-make-firefox-load-faster-known-firefox-tweaks_t39012.html
Firefox vs. Internet Explorer
Names
Internet Explorer – Microsoft leaves no doubt what their products are. If they made toilet paper it would be called Butt Wiper. Internet Explorer isn’t a bad name, but it’s not spectacular.
Firefox – On the other end of the spectrum, the name Firefox gives no clue to what it is. Could be a car? 80s video game? Lame comic book superhero? Flaming dish at a wild game restaurant? A browser would probably be your last guess. No matter, it is a much cooler name than the utilitarian Internet Explorer.
Winner: Firefox
Domain Names
Firefox – firefox.com Some kind soul donated the domain to the Mozilla Foundation. At least they own their own domain name.
Internet Explorer – internetexplorer.com Microsoft doesn’t even own this one. It’s one of those generic search portals masquerading as an IE site.
Winner: Firefox
Mascots
Internet Explorer – The big blue e with a swirly around it. A nice simple graphic, but not necessarily a mascot. However, with Microsoft’s history of mascots (Clippy, Bob), maybe it’s better they just stick with a letter.
Firefox – A giant fox with his tail on fire attacking the earth. That’s the stuff of nightmares. Not as scary as a communist Godzilla but close. It’s a cool graphic but Internet Explorer has to win something doesn’t it?
Winner: Internet Explorer
Google Fights
Why does Internet Explorer crash all the time? – 2.57 million results
Vs.
Why does Firefox crash all the time? – 218,000 results
Next…
Internet Explorer – 22.8 million results
Vs.
Firefox – 23 million results
That one is definitely a surprise.
Next…
Internet Explorer will help me get laid – 1.34 million results
Vs.
Firefox will help me get laid – 75,700 results
A much better chance of getting lucky with IE.
Next…
Internet Explorer came with my computer – 6.9 million results
Vs.
Firefox came with my computer – 659,000 results
Tie breaker…
Internet Explorer is the best browser ever – 2,110,000 results
Vs.
Firefox is the best browser ever – 474,000 results
Winner: Internet Explorer
Coin Flip – Best of 7
The coin flip was conducted using a 2000 Sacajawea dollar.
Internet Explorer – Heads
Firefox – Tails
Results: H-T-T-T-T-H-T
Winner: Firefox
Stereotypical User
Internet Explorer – Brain dead newbie. Loves pop-ups, viruses, and spyware. Just wants to “surf the Internet and check my email.” Oblivious to alternative lifestyles. Seeks help from “computer smart” nephew.
Firefox – Proselytizing ubergeek. Loves freedom, choice, and tabbed browsing. Just wants to “improve mankind with Open Source Software.” Oblivious to market forces and the power of money. Seeks other geeks to join in on the evangelism.
Both are equally annoying.
Winner: Even
Conclusions
In the end, it’s all about you being able to do what you need to do on the Web
source : http://www.bbspot.com/News/2005/01/firefox_vs_internet_explorer.html