473,378 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Brain has stopped - help pleas - ASPImage

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 1583
jhardman
3,406 Expert 2GB
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 Expert 2GB
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
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...
0
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...
7
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...
3
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...
7
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...
0
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...
95
by: viv342 | last post by:
how can two variables be swapped without using a third variable?
1
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...
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.