tritriada.blogg.se

Php image resize on the fly
Php image resize on the fly







  1. #Php image resize on the fly how to
  2. #Php image resize on the fly code

But the user has to know whichever method u r using and has to operate on the new size returned in the same manner.

php image resize on the fly

Put the width into a long (or ulong), shift it left 16 times and or it with ur height and return a single ulong which has both parameters as sort of packed into one variable. Or u can use a structure to do that.Īs a non nice hack u can mask upper 16 bits of width and height, unless u r working with images which may have a size more than 65535, which is unlikely. Its bool and so is checkbox so that gets done automatically.Ībout returning w & h back to caller, we can not return 2 values, so to do that u might create an array with 2 elements and put width height into array and return it.

php image resize on the fly

While calling the resize, use your checkbox status as last parameter. The preserveAspectRatio would probably be a check box in you code.

#Php image resize on the fly how to

I'm not a vb person but I can suggest the idea and u can see how to do it in vb. In this example, I simply read the original image from disk and then save the resized image to a MemoryStream for use later in the application: We can then call the method at an appropriate point to resize the image. GraphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight) GraphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic

php image resize on the fly php image resize on the fly

Using graphicsHandle As Graphics = Graphics.FromImage(newImage) NewHeight = CInt(originalHeight * percent)Įnd If Dim newImage As Image = New Bitmap(newWidth, newHeight)

#Php image resize on the fly code

Copy Code ' Visual Basic Public Shared Function ResizeImage( ByVal image As Image, _īyVal size As Size, Optional ByVal preserveAspectRatio As Boolean = True) As Imageĭim newWidth As Integer Dim newHeight As Integer If preserveAspectRatio Then Dim originalWidth As Integer = image.Widthĭim originalHeight As Integer = image.Heightĭim percentWidth As Single = CSng(size.Width) / CSng(originalWidth)ĭim percentHeight As Single = CSng(size.Height) / CSng(originalHeight)ĭim percent As Single = If(percentHeight < percentWidth,









Php image resize on the fly