/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/handlers/texttoimage.ashx
83 строки
3 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
<%@ WebHandler Language="VB" Class="textToImage" %> Imports System Imports System.Web Imports System.Math Imports System.Drawing.Imaging Imports System.Drawing Public Class textToImage : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim message As String Dim fontName As String Dim fontSize As Integer Dim backgroundColor As String Dim color As String Dim fontBold As String message = context.Request.QueryString("text") fontName = context.Request.QueryString("font") backgroundColor = context.Request.QueryString("backgroundcolor") color = context.Request.QueryString("color") fontBold = context.Request.QueryString("bold") 'Font setup Try fontSize = context.Request.QueryString("size") If fontSize = 0 Then fontSize = 100 End If Catch ex As Exception fontSize = 12 End Try If IsNothing(fontName) Then fontName = "Arial" End If If IsNothing(backgroundColor) Then backgroundColor = "White" End If If IsNothing(color) Then Color = "Black" End If Dim fStyle As FontStyle If fontBold = "Yes" Then fStyle = FontStyle.Bold Else fStyle = FontStyle.Regular End If 'Measure text width and height Dim objBmpImage As Drawing.Bitmap = New Bitmap(1, 1) Dim intWidth As Integer = 0 Dim intHeight As Integer = 0 ' Create the Font object for the image text drawing. Dim objFont As Font = New Font(fontName, fontSize, fStyle) ', System.Drawing.GraphicsUnit.Pixel) ' Create a graphics object to measure the text's width and height. Dim objGraphics As Graphics = Graphics.FromImage(objBmpImage) ' This is where the bitmap size is determined. intWidth = Int(objGraphics.MeasureString(message, objFont).Width) intHeight = Int(objGraphics.MeasureString(message, objFont).Height) Dim b As New Drawing.Bitmap(intWidth, intHeight, Drawing.Imaging.PixelFormat.Format32bppArgb) Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(b) g.Clear(Drawing.Color.FromName(backgroundColor)) g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias g.DrawString(message, New Drawing.Font(fontName, fontSize, fStyle), New Drawing.SolidBrush(Drawing.Color.FromName(color)), New Drawing.PointF(0.0F, 0.0F)) context.Response.ContentType = "image/gif" b.Save(context.Response.OutputStream, ImageFormat.Gif) b.Dispose() End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class