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)
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
jhardman 3,406
Recognized Expert Specialist
after thinking some more, I muscled through it. Here's the solution, a 32-byte one pixel image: - <%
-
option explicit
-
-
'set gifHeader
-
dim gifHeader, fileBytes(31), x
-
-
gifHeader = "GIF87a" 'there's also a version "89a", definition and syntax is
-
' almost identical, I'm not sure what the differences are.
-
-
x = 0
-
do until len(gifHeader) = 0
-
fileBytes(x) = AscB(left(gifHeader, 1))
-
gifHeader = right(gifHeader, len(gifHeader)-1)
-
x = x + 1
-
loop
-
-
'set image size
-
dim imgWidth, imgHeight
-
imgWidth = 1
-
imgHeight = 1
-
-
if imgWidth > 255 then
-
'need to shorten, first send "lsb"
-
'i'm glad I didn't need to calculate this.
-
else
-
fileBytes(x) = imgWidth
-
x = x + 1
-
fileBytes(x) = 0
-
x = x + 1
-
end if
-
-
if imgHeight > 255 then
-
'need to shorten, first send "lsb"
-
'i'm glad I didn't need to calculate this.
-
else
-
fileBytes(x) = imgheight
-
x = x + 1
-
fileBytes(x) = 0
-
x = x + 1
-
end if
-
-
'set color map, color resolution, and bits per pixel
-
dim M, CR, bpp
-
-
M = 1
-
CR = 0
-
bpp = 0
-
-
fileBytes(x) = bpp
-
fileBytes(x) = fileBytes(x) + (CR*16)
-
fileBytes(x) = fileBytes(x) + (M*128)
-
x = x + 1
-
-
'set background color
-
fileBytes(x) = 0 'first color in the dictionary
-
x = x + 1
-
-
'end screen descriptor
-
fileBytes(x) = 0
-
x = x + 1
-
-
'start color dictionary
-
fileBytes(x) = 255 'red index of first color
-
x = x + 1
-
fileBytes(x) = 255 'green index of first color
-
x = x + 1
-
fileBytes(x) = 0 'blue index of first color
-
x = x + 1
-
-
fileBytes(x) = 255 'red index of 2nd color
-
x = x + 1
-
fileBytes(x) = 255 'green index of 2nd color
-
x = x + 1
-
fileBytes(x) = 0 'blue index of 2nd color
-
x = x + 1
-
-
'start first image
-
fileBytes(x) = 44 ' comma is the first character of an image
-
x = x + 1
-
-
'positioning of image within total file
-
fileBytes(x) = 0 ' start in the corner, horiz (lsb format)
-
x = x + 1
-
fileBytes(x) = 0 ' more significant byte is 0 (number < 255)
-
x = x + 1
-
fileBytes(x) = 0 ' start in the corner, vert
-
x = x + 1
-
fileBytes(x) = 0 ' more significant byte
-
x = x + 1
-
-
'dimensions of this image
-
fileBytes(x) = 1 ' image width (lsb format)
-
x = x + 1
-
fileBytes(x) = 0 ' more significant byte is 0 (number < 255)
-
x = x + 1
-
fileBytes(x) = 1 ' image height
-
x = x + 1
-
fileBytes(x) = 0 ' more significant byte
-
x = x + 1
-
-
'use global color map
-
fileBytes(x) = 0 ' no local color map, just use global
-
x = x + 1
-
-
'start raster data, I'm still not sure about compression, but for one pixel:
-
fileBytes(x) = 0 'first color in color map
-
x = x + 1
-
-
fileBytes(x) = 1
-
x = x + 1
-
-
'end the file
-
fileBytes(x) = 59 'last byte is a semi colon, ends each image
-
-
for each x in fileBytes
-
if x <> "" then
-
response.write x & " "
-
end if
-
next
-
response.write "<br>" & vbNewLine
-
-
-
dim output
-
for each x in fileBytes
-
if x <> "" then
-
response.write chr(x) & " "
-
output = output & chr(x)
-
end if
-
next
-
-
'save file
-
dim objFSO, objTXT, filePath, fileName
-
filePath = request.serverVariables("appl_physical_path") & "temp"
-
fileName = "ffff00.gif"
-
filePath = filePath & "\" & fileName
-
response.write "<!-- path: " & filePath & " -->" & vbNewLine
-
set objFSO = server.createObject("scripting.fileSystemObject")
-
set objTXT = objFSO.openTextFile (filePath, 2, True)
-
objTXT.write output
-
response.write "<br>(File saved as: " & filePath & ")<br>" & vbNewLine
-
response.write "<img src='" & fileName & "'><br>" & vbNewLine
-
-
'spacer gif: 71 73 70 56 55 97 1 0 1 0 128 0 0 255 255 0 0 0 0 44 0 0
-
' 0 0 1 0 1 0 0 0 0 59
-
'yellow gif: 71 73 70 56 55 97 1 0 1 0 128 0 0 255 255 0 255 255 0 44
-
' 0 0 0 0 1 0 1 0 0 0 1 59
-
%>
-
<div style="background-color: blue;">
-
<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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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.
|
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
|
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...
| |
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.
|
by: viv342 |
last post by:
how can two variables be swapped without using a third variable?
|
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
|
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
----------------------
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |