Creating thumbnail images is a very common requirement. Many scripts use this to create thumbnails of uploaded images or any stored images. We will learn how to create thumbnail images while uploading images to the server. Please read the tutorials on file upload when register_global is off to know how to upload files to the server with necessary permissions in PHP 5.
The file ( or image ) will be first uploaded to a directory and then one thumbnail image will be created in a different directory. So for creating the thumbnail we will check the file extension ( it is gif or jpeg image ) but to keep the script simple we are not checking here the file size. So if the file size is to be restricted then file size validation is to be added. You can see how the file size checking is done in file upload tutorial.
This script is tested with PHP 5.2.6 with register_global is OFF. Please update your script if you have downloaded the old version of this.
We will now see the addimgck.php file and check the code to create the thumbnail image. We will upload the file to the upimg directory and check to see if file upload is successful or not.
}else{echo “Failed to upload file Contact Site admin to fix the problem”;
exit;}
Now the image is uploaded to the directory and from that image we will create thumbnail image of it. We will first set the height and width of the thumbnail images to be generated. Then we will check the type of the file and now we are checking for file type of gif and jpeg and if the image is not of this type then we are terminating the script giving an error message.
$tsrc=”thimg/”.$_FILES[userfile][name]; // Path where thumb nail image will be stored
//echo $tsrc;
if (!($_FILES[userfile][type] ==”image/pjpeg” OR $_FILES[userfile][type]==”image/gif”)){echo “Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>”;
exit;}
Now let us start with gif file thumb nail image creation. We will first read the height and width of the uploaded image and then resize it to our thumbnail image size. Note that in some GD library support GIF version is not included so to check that we have used one if condition and accordingly used jpeg support. We will be using imagecreatetruecolor to retain the actual color combination of the main picture.
////////////// starting of JPG thumb nail creation//////////
if($_FILES[userfile][type]==”image/pjpeg”){
$im=ImageCreateFromJPEG($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
chmod(“$tsrc”,0777);
}
//////////////// End of JPG thumb nail creation //////////
Hürriyetin sitesine göre ayarlanmıştır. Kodu ceviz den almıştım biraz değiştirdim.
Etiketler: php ile yazı çekmek, php rss konu çekmek, rss çeken php kod, rss ekmek, yazı çeken php kod
CSharp ile ilgili yazılarıma bundan sonra www.csharpkitabi.com sitemde devam edeceğim.
Etiketler: csharp
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false && e.KeyChar!=8)
e.KeyChar = ‘\0′;
}
Etiketler: backspace tuşu çalışsın, csharp backspace, sayı girerken silme tuşuda çalışsın, sayı girişinde backspace tuşu, textbox a sayı girişi, textBox'a Sadece sayı girilsin
textBox’ın keypress olayına aşağıdaki kodu yazıyoruz.
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string str = “0123456789″;
if (str.IndexOf(e.KeyChar) == -1)
e.KeyChar = ‘\0′;
}
Etiketler: csharp sayı kontrolü, sayı kontrol fonksiyonu, textbox a sayımı girildi, textbox sayı kontrolü
Link konu aşağıdaki gibi yazılır.
<a href=”http://www.seoarşivi.com” title=”Seo Arşivi” >Seo Arşivi</a>
Yeni sekmede açtırmak için target=” _blank ” kodunu href ten önce ekliyoruz ve _blank kelimesinin önüne ve sonuna bir karakter boşluk bırakıyorsunuz tırnakların içerisine.
<a target=” _blank ” href=”http://www.seoarşivi.com” title=”Seo Arşivi” >Seo Arşivi</a>
Etiketler: html yeni sekme, sekme açtırmak, sekmeye link verme, yeni pencereyi sekmede açtırmak
Klavyeden girilecek bir sayının asal sayı olup olmadığını ekrana basan bir program yazınız
int sayi, i;
//Sayıyı ilk başta asal kabul ediyoruz.
//asal_mi değişkeni 1 ise, sayi asaldir.
int asal_mi = 1;
//Klavyeden, test edilmek üzere bir sayı alınıyor.
sayi =Convert.ToInt32(Console.ReadLine());
//Girilen sayının, başka sayılara göre sırayla modunu
//alıyoruz. Bir sayının modunu aldığınızda, kalan 0 ise
//bu sayının bölünebildiğine ve dolayısıyla
//asal olmadığına dair bilgi verir. Bu işlemi yapabilmek
//için 2′den başlayarak, sayının yarısına kadar olan
//bütün değerler deneniyor.
for( i = 2; i < sayi; i++ ) {
if( sayi%i == 0 ) {
//Sayı i değişkenine kalansız bölünmektedir.
//Dolayısıyla, sayı asal değildir ve döngüyü
//sürdürmeye gerek yoktur.
asal_mi = 0;
break;
}
}
//Sayının asal olup olmama durumuna göre, çıktı yazdırılıyor.
if( asal_mi == 1 )
Console.WriteLine( “{0} sayısı asaldır.\n”, sayi );
else
Console.WriteLine( “{0} sayısı asal değildir.\n”, sayi );
Etiketler: asal sayı değilmi, asal sayı örneği, asal sayımı, c# console, Console Aplication
Bir üçgende, iki kenarın toplam uzunluğu, üçüncü kenardan az olamaz. Ayrıca iki kenarın birbirinden farkının mutlak değeri, üçüncü kenardan büyük olmamalıdır. Bu bilgileri kullanarak, verilen üç kenar uzunluğuna göre bir üçgen çizilip çizilmeyeceğini gösteren programı yazınız. Girilecek kenar uzunlukları tam sayı olacaktır.
int a, b, c;
int temp;
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
/* a ile b den buyuk olan a ya kucuk olan b ye atanir */
if (a < b)
{
temp = a;
a = b;
b = temp;
}
if (((a + b) <= c) || ((a – b) >= c))
Console.WriteLine(“Bu kenar uzunluklarina sahip bir ucgen olamaz.\n”);
else
Console.WriteLine(“Bu kenar uzunluklarina sahip bir ucgen cizilebilir.\n”);
Etiketler: c sharp üçgen kontrolü, üçgenmi değilmi