473,804 Members | 2,962 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Brain has stopped - help pleas - ASPImage

1 New Member
Good Morning Folks

I have bought and own a copy of ASPImage.
Installed on my Internet server.
Works like a Dream writing and saving image files containing text.


My brain seems to have stopped working.
I have tried to write a script that I expect cannot be more than ten lines long.
The towel has been thrown in !!


Then I thought some kind person in this forum could produce it in five minutes.


So please will anyone help


The task is simple.

I have a variable called
hColor
It contains (for example) "FFFF00" (for Yellow) (Note - no hash)



I want to create and save a "one pixel" by "one pixel" image of the color held in 'hColor'

The image file name is (in this case)
FFFF00_dot.gif


I will be forever in your debt
Thanks (in anticipation)
Pete (Northolt UK)
Aug 12 '07 #1
2 1606
jhardman
3,406 Recognized Expert Specialist
Pete,

I've been thinking about this problem for a while, unfortunately, the best solution I can come up with is to save a single-pixel-image using paint or some such and then opening the bytes to figure what they say. I know for example that the beginning of the file says "GIF89a" and then the dimensions of the picture, but after that the data is compressed, I understand how the compression works, at least the theory behind it, but I don't think I could count backwards enough to read the data file. I had an old example of how to write a small 15 X 15 gif image, and sure enough it starts out "71 73 70 56 57 97 15 0 15 0", but after that I'm lost.

To make matters worse, when I tried to make a one pixel image in paint and then look at the bytes, the image starts out the same "71 73 70 56 55 97 1 0 1 0" as expected, but the file is actually much longer than the 15 X 15 image, ( I suspect that paint pads the file a bit, and it uses the old '87a' version, notice the difference of the 5th character) and I can see no pattern, either declaration of the compression library or anything. If you could elucidate the idea of what the file should look like, I could show you how to save the file, it's just coming up with the right sequence of numbers that is beyond me.

Jared
Aug 20 '07 #2
jhardman
3,406 Recognized Expert Specialist
after thinking some more, I muscled through it. Here's the solution, a 32-byte one pixel image:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. option explicit
  3.  
  4. 'set gifHeader
  5. dim gifHeader, fileBytes(31), x
  6.  
  7. gifHeader = "GIF87a" 'there's also a version "89a", definition and syntax is
  8.     ' almost identical, I'm not sure what the differences are.
  9.  
  10. x = 0
  11. do until len(gifHeader) = 0
  12.     fileBytes(x) = AscB(left(gifHeader, 1))
  13.     gifHeader = right(gifHeader, len(gifHeader)-1)
  14.     x = x + 1
  15. loop
  16.  
  17. 'set image size
  18. dim imgWidth, imgHeight
  19. imgWidth = 1
  20. imgHeight = 1
  21.  
  22. if imgWidth > 255 then
  23.     'need to shorten, first send "lsb"
  24.     'i'm glad I didn't need to calculate this.
  25. else
  26.     fileBytes(x) = imgWidth
  27.     x = x + 1
  28.     fileBytes(x) = 0
  29.     x = x + 1
  30. end if
  31.  
  32. if imgHeight > 255 then
  33.     'need to shorten, first send "lsb"
  34.     'i'm glad I didn't need to calculate this.
  35. else
  36.     fileBytes(x) = imgheight
  37.     x = x + 1
  38.     fileBytes(x) = 0
  39.     x = x + 1
  40. end if
  41.  
  42. 'set color map, color resolution, and bits per pixel
  43. dim M, CR, bpp
  44.  
  45. M = 1
  46. CR = 0
  47. bpp = 0
  48.  
  49. fileBytes(x) = bpp
  50. fileBytes(x) = fileBytes(x) + (CR*16)
  51. fileBytes(x) = fileBytes(x) + (M*128)
  52. x = x + 1
  53.  
  54. 'set background color
  55. fileBytes(x) = 0 'first color in the dictionary
  56. x = x + 1
  57.  
  58. 'end screen descriptor
  59. fileBytes(x) = 0
  60. x = x + 1
  61.  
  62. 'start color dictionary
  63. fileBytes(x) = 255 'red index of first color
  64. x = x + 1
  65. fileBytes(x) = 255 'green index of first color
  66. x = x + 1
  67. fileBytes(x) = 0 'blue index of first color
  68. x = x + 1
  69.  
  70. fileBytes(x) = 255 'red index of 2nd color
  71. x = x + 1
  72. fileBytes(x) = 255 'green index of 2nd color
  73. x = x + 1
  74. fileBytes(x) = 0 'blue index of 2nd color
  75. x = x + 1
  76.  
  77. 'start first image
  78. fileBytes(x) = 44 ' comma is the first character of an image
  79. x = x + 1
  80.  
  81. 'positioning of image within total file
  82. fileBytes(x) = 0 ' start in the corner, horiz (lsb format)
  83. x = x + 1
  84. fileBytes(x) = 0 ' more significant byte is 0 (number < 255)
  85. x = x + 1
  86. fileBytes(x) = 0 ' start in the corner, vert
  87. x = x + 1
  88. fileBytes(x) = 0 ' more significant byte
  89. x = x + 1
  90.  
  91. 'dimensions of this image
  92. fileBytes(x) = 1 ' image width (lsb format)
  93. x = x + 1
  94. fileBytes(x) = 0 ' more significant byte is 0 (number < 255)
  95. x = x + 1
  96. fileBytes(x) = 1 ' image height
  97. x = x + 1
  98. fileBytes(x) = 0 ' more significant byte
  99. x = x + 1
  100.  
  101. 'use global color map
  102. fileBytes(x) = 0 ' no local color map, just use global
  103. x = x + 1
  104.  
  105. 'start raster data, I'm still not sure about compression, but for one pixel:
  106. fileBytes(x) = 0 'first color in color map
  107. x = x + 1
  108.  
  109. fileBytes(x) = 1
  110. x = x + 1
  111.  
  112. 'end the file
  113. fileBytes(x) = 59 'last byte is a semi colon, ends each image
  114.  
  115. for each x in fileBytes
  116.     if x <> "" then
  117.         response.write x & " "
  118.     end if
  119. next 
  120. response.write "<br>" & vbNewLine
  121.  
  122.  
  123. dim output
  124. for each x in fileBytes
  125.     if x <> "" then
  126.         response.write chr(x) & " "
  127.         output = output & chr(x)
  128.     end if
  129. next
  130.  
  131. 'save file
  132. dim objFSO, objTXT, filePath, fileName
  133. filePath = request.serverVariables("appl_physical_path") & "temp"
  134. fileName = "ffff00.gif"
  135. filePath = filePath & "\" & fileName
  136. response.write "<!-- path: " & filePath & " -->" & vbNewLine
  137. set objFSO = server.createObject("scripting.fileSystemObject")
  138. set objTXT = objFSO.openTextFile (filePath, 2, True)
  139. objTXT.write output
  140. response.write "<br>(File saved as: " & filePath & ")<br>" & vbNewLine
  141. response.write "<img src='" & fileName & "'><br>" & vbNewLine
  142.  
  143. 'spacer gif: 71 73 70 56 55 97 1 0 1 0 128 0 0 255 255 0 0 0 0 44 0 0
  144. ' 0 0 1 0 1 0 0 0 0 59 
  145. 'yellow gif: 71 73 70 56 55 97 1 0 1 0 128 0 0 255 255 0 255 255 0 44
  146. ' 0 0 0 0 1 0 1 0 0 0 1 59
  147. %>
  148. <div style="background-color: blue;">   
  149. <img src='<%= fileName %>' height='30' width='30'></div>
There are a few tricky parts. First, the image size is defined more than once, because a gif file can hold more than one image (for animations, etc.). The first time is the total, all subsequent times are for individual pictures.

Second, the color map, color resolution and bits per pixel is combined into one byte. That makes that byte a little tricky to calculate. You can also define a different color map for each image, I just defined a single "global" color map and on the actual image left it blank.

Third, you need at least two colors defined. If you only use a single color, it doesn't matter what the second color is.

Fourth, image size and image placement numbers are in 2 byte LSB format, which means if the number is less than 255, you just use the first byte and leave the second byte at 0. (that makes a 1 x 1 pixel picture say "1 0 1 0") If the number is greater than 255 you need to use both bytes, and I'm glad I didn't need to calculate what the second byte was.

Fifth, (the really tricky one) is the compression formula. Fortunately this only applies to the raster data, so if you only have one pixel, the raster data should say (0 1) for the first color in your color map or (0 0) for transparent.

Jared
Aug 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2487
by: Fredo Vincentis | last post by:
Hi guys, this is not really an ASP question, but some of you might have had experience with this and I thought you migth be able to help me. I require the ASP componentn ASPImage for one of my projects. Unfortunately, my webhost does not have this component installed. If I personally buy it, do you think I will be able to install it on the server, or is that something the webhost has to do? Sorry, I have never had to deal with this...
0
1818
by: Mohamed Hosam | last post by:
I want to use ASPImage to resize photos and show them to user as thumbnails on the fly (I do not want to save them). Any idea how to achieve this? On their page, they advise me to use Response.BinaryWrite, so this is what I did: Response.ContentType = "Image/Jpeg" Response.BinaryWrite Image.FileName Instead of showing the image, it shows the binary contents!! Any help is
7
2610
by: Ford Prefect alias Armin | last post by:
I want to start a Thread and wait till the Thread has been stopped (via Suspend) How to do this. Sub Test Start Thread Wait Till Stopped Go on with this code as sone as the Thread has stopped.
3
5058
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from the network share. It loads in VS2005 fine, and I can edit and save code changes etc, but when I try and Build the solution, I get the following error... An error occured loading a configuration file: Failed to start monitoring
7
10640
by: Mark A | last post by:
If server 01 running HADR in the primary role crashes, and the DBA does a HADR takeover by force on the 02 server to switch roles, then the 02 server is now the primary. What happens when the Server 01 is brought back up? It still thinks it is the primary because that was its role when it crashed and it does not know about the takeover by force command that was issued. Does the 01 server check the 02 server to see what role they are in...
0
1296
by: Kelly | last post by:
Help, So I'm doing the common make thumbnails script. to save server space, I don't want to store the thumbnails, so I did the classic break up script. I parse on the main page where it gathers the folders, files and their paths, then I pass them over into the sendbinary.asp page which does all the editing. First of all this works.
95
4326
by: viv342 | last post by:
how can two variables be swapped without using a third variable?
1
1207
by: himanshu110 | last post by:
HI guys im fed up with this help me The problem is.. Im having a repeater control in which im having a aspImage Control imgAImageUpload"]..just near to it is a href placed Both are placed in a repeater Row as a RowContrl
4
1111
by: ramorac | last post by:
hi my requirement is something like this.. say.. there are two columns A and B. In B there are values b1 b2 b3 b4..... the output should be.. --------------------- Column_Name ----------------------
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.