logo

Javascript Resim Resize Boyutlandırma

logo

Javascript ile resim boyutlandırmak için bir kod aramaktaydım. öyle ki resmin genişliği veya yüksekliği farklı ise istediğim maksimum genişlik ve yüksekliğe ölçeklemesini istiyordum. bunun için şurada güzel bir kod buldum. umarım işinize yarar

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function ResizeImage(image, maxwidth, maxheight)
{
    if (image.className == "Thumbnail")
    {
        w = image.width;
        h = image.height;
 
        if( w == 0 || h == 0 )
        {
            image.width = maxwidth;
            image.height = maxheight;
        }
        else if (w > h)
        {
            if (w > maxwidth) image.width = maxwidth;
        }
        else
        {
            if (h > maxheight) image.height = maxheight;
        }
 
        image.className = "ScaledThumbnail";
    }
}

bu kodu <head> </head> tagları arasına alacaksınız
örnek kullanımı da şöyle
< img src=”resim.jpg” class=”Thumbnail” onload=”ResizeImage(this, 200, 250)” />
200 maksimum genişlik, 250 ise maksimum yüksekliği gösterir onları isteğinize göre değiştirebilirsiniz
eğer resim önceden başka bir class adına sahipse, mesela resimclassı diye, class adı şu şekilde olacak
class=”resimclassı Thumbnail”

VN:F [1.9.3_1094]
Rating: 8.0/10 (6 votes cast)
VN:F [1.9.3_1094]
Rating: -1 (from 1 vote)
Javascript Resim Resize Boyutlandırma, 8.0 out of 10 based on 6 ratings
blog comments powered by Disqus
logo
logo
Powered by Wordpress | Designed by Elegant Themes