Unfortunately I don't have support for IIS, if you know of a PHP alternative I would be extremely grateful.

Thank you again Philip for the code and the help !

Christopher

Philip Taylor <mailto:p.tay...@rhul.ac.uk>
Friday, November 07, 2014 5:42 PM
Crest Christopher wrote:

I've always wanted to add a watermark to images automatically when
uploaded to the server for display on the page.  Can you customize the
watermark ?

Of course :  see the code fragment below.

My only problem is I have to check if I can support IIS,
which is faster IIS or PHP ?

Absolutely no idea, Christopher, but my code works only on IIS.

Philip Taylor
--------
<script language="C#" runat="server">

public bool ThumbnailCallback () {return false;}

public void Page_Load (object sender, EventArgs e)
{
        int max = 30;
        int min = 1;
        string imageURL = Request.QueryString ["img"];
        int imageMax = Convert.ToInt32 (Request.QueryString ["max"]);
        int xOffset = 0, imageWidth = 0, imageHeight = 0;
        imageURL =
"D:\\Web\\Sites\\Org\\For-Charity\\Photos\\Resources\\Images\\Private\\"
+ imageURL;
        System.Drawing.Image fullSizeImg = null;
        fullSizeImg = System.Drawing.Image.FromFile (imageURL);
        int CurrentimgHeight = fullSizeImg.Height;
        int CurrentimgWidth = fullSizeImg.Width;
        if (CurrentimgHeight>  CurrentimgWidth)
                {
                        imageHeight = imageMax;
                imageWidth = Convert.ToInt32 ( (1.0 * CurrentimgWidth) / (1.0 *
CurrentimgHeight) * imageHeight);
                }
        else
                {
                        imageWidth = imageMax;
                imageHeight = Convert.ToInt32 ( (1.0 * CurrentimgHeight) / (1.0 
*
CurrentimgWidth) * imageWidth);
                };
        Response.ContentType = "image/jpeg";
        System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = null;
        dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort
(ThumbnailCallback);
        System.Drawing.Image thumbNailImg = null;
        thumbNailImg = fullSizeImg.GetThumbnailImage (imageWidth, imageHeight,
dummyCallBack, IntPtr.Zero);
        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage
(thumbNailImg);
        SizeF StringSizeF = default (SizeF);
        float DesiredWidth = 0;
        Font wmFont = default (Font);
        float RequiredFontSize = 0;
        float Ratio = 0;
        String strWatermark = "Copyright  ©  2010";
        String strWatermarkowner = Request.QueryString ["wmo"];
        float xdelta = 0;
        float ydelta = 0;
        wmFont = new Font ("Arial", 24, FontStyle.Bold);
        DesiredWidth = Convert.ToInt32 (imageWidth * 0.85);
        xOffset = Convert.ToInt32 ( (imageWidth - DesiredWidth) / 2);
        StringSizeF = g.MeasureString (strWatermark, wmFont);
        Ratio = StringSizeF.Width / wmFont.SizeInPoints;
        RequiredFontSize = DesiredWidth / Ratio;
        wmFont = new Font ("Arial", RequiredFontSize, FontStyle.Bold);
        xdelta = 0; // imageWidth / 25;
        ydelta = imageWidth / 20;
        g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        g.DrawImage (fullSizeImg, 0, 0, imageWidth, imageHeight);
        g.SmoothingMode = SmoothingMode.HighQuality;
        SolidBrush letterBrush = new SolidBrush (Color.FromArgb (50, 255, 255,
255));
        SolidBrush shadowBrush = new SolidBrush (Color.FromArgb (50, 0, 0, 0));
        g.DrawString (strWatermark, wmFont, shadowBrush, Convert.ToSingle
(xOffset * 1.0) , Convert.ToSingle ( (imageHeight * 0.5) - 2.25 * ydelta));
        g.DrawString (strWatermark, wmFont, letterBrush, Convert.ToSingle (
(xOffset + 3) * 1.0), Convert.ToSingle ( (imageHeight * 0.5) + 2 - 2.25
* ydelta));
        wmFont = new Font ("Arial", 24, FontStyle.Bold);
        StringSizeF = g.MeasureString (strWatermarkowner, wmFont);
        Ratio = StringSizeF.Width / wmFont.SizeInPoints;
        RequiredFontSize = DesiredWidth / Ratio;
        wmFont = new Font ("Arial", RequiredFontSize, FontStyle.Bold);
        g.DrawString (strWatermarkowner, wmFont, shadowBrush, Convert.ToSingle
(xOffset - xdelta), Convert.ToSingle ( (imageHeight * 0.5)  + 0.25 *
ydelta));
        g.DrawString (strWatermarkowner, wmFont, letterBrush, Convert.ToSingle
(xOffset + 3 - xdelta), Convert.ToSingle ( (imageHeight * 0.5) + 2 +
0.25 * ydelta));
        Matrix myMatrix = new Matrix ();
Crest Christopher <mailto:crestchristop...@gmail.com>
Friday, November 07, 2014 5:32 PM
I've always wanted to add a watermark to images automatically when uploaded to the server for display on the page. Can you customize the watermark ? My only problem is I have to check if I can support IIS, which is faster IIS or PHP ?

Christopher

Philip Taylor <mailto:p.tay...@rhul.ac.uk>
Friday, November 07, 2014 9:21 AM


Crest Christopher wrote:


Well, your server needs to be running IIS (Microsoft Internet Information Server) and then you just drop the .aspx and .aspx.vb or .aspx.js files into the appropriate locations on the server. I imagine that if your server does not run IIS then there may be alternative technologies such as PHP that can accomplish much the same thing, but I personally know nothing about such server-side technologies.

Philip Taylor
Crest Christopher <mailto:crestchristop...@gmail.com>
Friday, November 07, 2014 9:16 AM
The only issue is the images hug the border of the browser, but that is a style issue ;-) How do you set this up using this Asp.Net code ? I like it better then image replacements as I don't notice the flicker when the image changes size.

Christopher

Philip Taylor <mailto:p.tay...@rhul.ac.uk>
Friday, November 07, 2014 9:08 AM


Crest Christopher wrote:


Bear in mind that that Asp.Net code is being run on a bog-standard home PC, several years old, and uploaded on a slow ADSL link that can manage barely 448kb uploads. If you found it fast even bearing those facts in mind, think how fast it would be on a T1-connected real server.

Philip Taylor
______________________________________________________________________
css-discuss [css-d@lists.css-discuss.org]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to