Page 1 of 1

Image resizing

Posted: Thu Aug 09, 2007 5:18 am
by aaanew
I have submit the coe for image resizing using dotnet.I need convert this methodology to PHP.Please anybody one help me.




Private Shared Function ResizeImageFile(ByVal imageFile() As Byte, ByVal targetSize As Integer) As Byte()

Using oldImage As System.Drawing.Image = System.Drawing.Image.FromStream(New MemoryStream(imageFile))

Dim newSize As Size = CalculateDimensions(oldImage.Size, targetSize)

Using newImage As Bitmap = New Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb)

Using canvas As Graphics = Graphics.FromImage(newImage)

canvas.SmoothingMode = SmoothingMode.AntiAlias

canvas.InterpolationMode = InterpolationMode.HighQualityBicubic

canvas.PixelOffsetMode = PixelOffsetMode.HighQuality

canvas.DrawImage(oldImage, New Rectangle(New Point(0, 0), newSize))

Dim m As New MemoryStream

newImage.Save(m, ImageFormat.Jpeg)

Return m.GetBuffer

End Using

End Using

End Using

End Function



Private Shared Function CalculateDimensions(ByVal oldSize As Size, ByVal targetSize As Integer) As Size

Dim newSize As Size

If (oldSize.Height > oldSize.Width) Then

newSize.Width = CType((oldSize.Width * CType((targetSize / CType(oldSize.Height, Single)), Single)), Integer)

newSize.Height = targetSize

Else

newSize.Width = targetSize

newSize.Height = CType((oldSize.Height * CType((targetSize / CType(oldSize.Width, Single)), Single)), Integer)

End If

Return newSize

End Function

Posted: Thu Aug 09, 2007 6:06 am
by dude81
Have a look at PHP-GD and its functions

Posted: Thu Aug 09, 2007 6:08 am
by superdezign
I don't know... rewrite it.

Use the GD Library. It's generally friendly for simple things like resizing. You may want too look at the imagecreate*() functions, the imagecopyresampled() function, and the image*() functions.