Question : .NET image resizing script for blog

I am looking for a script which can be used for a internal blog which can resize images to the specified dimensions after user uploads any size of image.
Or a script which can create thumbnails on front end and keeps original image on back end so whenever clicked on thumbnail original image can be opened in new window.

Answer : .NET image resizing script for blog

thanx to Ali NARIN for the codes
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
Public Shared Function ImageResize(ByVal source As String, _
                                        ByVal destination As String, _
                                              Optional ByVal newWidth As Integer = 0, _
                                              Optional ByVal newHeight As Integer = 0, _
                                              Optional ByVal NewIsMax As Boolean = False, _
                                              Optional ByVal Smoothing As Drawing2D.SmoothingMode = SmoothingMode.HighQuality, _
                                              Optional ByVal Compositing As Drawing2D.CompositingQuality = CompositingQuality.HighQuality, _
                                              Optional ByVal Interpolation As Drawing2D.InterpolationMode = InterpolationMode.High) As Boolean
      Try
         Dim fullSizeImage As Image
         fullSizeImage = Image.FromFile(source)

         Dim w As Integer = fullSizeImage.Width
         Dim h As Integer = fullSizeImage.Height

         If newWidth <= 0 And newHeight <= 0 Then
            newWidth = w
            newHeight = h
         End If

         If Not NewIsMax Then 'verilen degerlere göre direk dönüstürür
            If newWidth > 0 And newHeight <= 0 Then newHeight = h * (newWidth / w)
            If newWidth <= 0 And newHeight > 0 Then newWidth = w * (newHeight / h)
         Else ' max deger kabul eder
            If (w / h) > 1 Then 'yatay resim
               'newHeight = h * (newWidth / w)
               If (h * (newWidth / w)) <= newHeight Then 'height de tasma yoksa
                  newHeight = h * (newWidth / w) 'yükseklik ayarla
               Else
                  newWidth = w * (newHeight / h) 'tasma varsa yükseklige dokunmadan genisligi küçült
               End If
            Else 'dikey resim
               'newWidth = w * (newHeight / h)
               If (w * (newHeight / h)) <= newWidth Then 'genslikte tasma yoksa
                  newWidth = w * (newHeight / h) 'genisligi ayarla
               Else
                  newHeight = h * (newWidth / w) 'tasma varsa genislige dokunmadan yüksekligi ayarla
               End If
            End If
         End If

         Dim imgTmp As Image
         Dim imgFoto As Bitmap

         imgTmp = Image.FromFile(source)
         imgFoto = New Bitmap(CInt(newWidth), CInt(newHeight))

         Dim recDest As New Rectangle(0, 0, newWidth, imgFoto.Height)
         Dim gphCrop As Graphics = Graphics.FromImage(imgFoto)
         gphCrop.SmoothingMode = Smoothing
         gphCrop.CompositingQuality = Compositing
         gphCrop.InterpolationMode = Interpolation

         gphCrop.DrawImage(imgTmp, recDest, 0, 0, imgTmp.Width, imgTmp.Height, GraphicsUnit.Pixel)

         Dim myEncoder As Imaging.Encoder
         Dim myEncoderParameter As EncoderParameter
         Dim myEncoderParameters As EncoderParameters

         Dim arrayICI() As Imaging.ImageCodecInfo = Imaging.ImageCodecInfo.GetImageEncoders()
         Dim jpegICI As Imaging.ImageCodecInfo = Nothing
         Dim x As Integer = 0
         For x = 0 To arrayICI.Length - 1
            If (arrayICI(x).FormatDescription.Equals("JPEG")) Then
               jpegICI = arrayICI(x)
               Exit For
            End If
         Next
         myEncoder = Imaging.Encoder.Quality
         myEncoderParameters = New Imaging.EncoderParameters(1)
         myEncoderParameter = New Imaging.EncoderParameter(myEncoder, 80L)
         myEncoderParameters.Param(0) = myEncoderParameter
         imgFoto.Save(destination, jpegICI, myEncoderParameters)

         imgFoto = Nothing
         imgTmp = Nothing
         imgFoto.Dispose()
         imgTmp.Dispose()
         Return True
      Catch ex As Exception
         Return False
      End Try
   End Function
Random Solutions  
 
programming4us programming4us