read .jpg files

iclbloom
Posts: 103
Joined: Mon May 07, 2001 5:51 pm

read .jpg files

Post by iclbloom »

I am attempting to read images into a texis database, the images are in .jpg files,

What data type should I make the field that will hold the .jpg "data". Should I use the BLOB type or byte.
Should I use the <read> tag to import the data.? i.e. <read $vthumbnail><$vthumbnaildata = $ret>

What tag should I use to "output" print the .jpg "data", <send> ?.
Is the best way to do print the image by createing a function that prints the image and reference that fuction as an <a href>?

Thanks
Leon Bloom
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

read .jpg files

Post by Kai »

If the images are very small, eg. no more than 3-5K apiece, a blob field is probably most efficient.

If the images are larger, an indirect field is better so that the table doesn't bloat and you avoid the 32-bit filesize limit (if applicable to your platform). Eg.:

<sql "create mytable(id counter, ImagePath indirect)"></sql>
<sql novars "insert into mytable values(counter, toind($Image))"></sql>

The toind() function creates a unique filename in the "indirects/" subdirectory of your database, and puts the contents of the value $Image there. When selecting the image, you can send it thusly:

<sql "select ImagePath from mytable"></sql>
<spew $ImagePath>

You can also <read $ImagePath> and print it with <fmt "%s" $ret> (do not use <send>, it is not binary-compatible).
iclbloom
Posts: 103
Joined: Mon May 07, 2001 5:51 pm

read .jpg files

Post by iclbloom »

In the 2nd line of your example is $Image supposed to be $ImagePath ?

<sql novars "insert into mytable values(counter, toind($Image))"></sql>


Either way what is in $Image (the filename or the data from the file) and what type is it.

In the documentation for toind it has a similar example using fromfile, how is fromfile used?

Thanks
Leon Bloom
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

read .jpg files

Post by Kai »

$Image is supposed to be your actual image data, not the path; eg.:

<read "/my/dir/image.jpg">
<$Image = $ret>

or from a multi-part file upload form, etc. $Image can be any binary data, whether it's an image, PDF, etc.

If your data is already in a file, and you wish to keep it in that file, you can simply insert that *path* into ImagePath:

<sql "insert into mytable values(counter, '/my/dir/image.jpg')"></sql>

The use of toind() is to create a Texis-managed file name under your database dir and insert the data there, if you don't already have the data stored in a file.

fromfile() reads from its file (path) argument and returns the data, so you could alternatively do:

<sql "insert into mytable values(counter, toind(fromfile('/my/dir/image.jpg'))"></sql>

if '/my/dir/image.jpg' is a *temporary* file with the image, and you want Texis to create a more permanent (and guaranteed unique) file name and store the data there.

It all depends on whether your data is currently image data, or a temporary file, or a permanent file.

(Also, note that for a browser to properly display an image, the function that prints the image must be linked to via <IMG SRC=...>, not <A HREF=...>.)
iclbloom
Posts: 103
Joined: Mon May 07, 2001 5:51 pm

read .jpg files

Post by iclbloom »

In your example:<sql "insert into mytable values(counter, '/my/dir/image.jpg')"></sql>

what is the data type of the 2nd column, indirect or varchar()?


in this example:
<sql "insert into mytable values(counter, toind(fromfile('/my/dir/image.jpg'))"></sql>

is the 2nd column an indirect?

Is there any problem w/ doing this insert in an timport routine.

does SET have any use here or is it strictly for UPDATE?

Is the problem I have having related to using the data type varind in TIMPORT?

Thanks
Leon Bloom
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

read .jpg files

Post by Kai »

In all examples above, the 2nd column (ImagePath) is indirect.

(As an aside, the column could just as well be varchar for these examples, because toind() creates the indirect file name. However, to make it clear that this is an indirect file, we use indirect instead of varchar. Also, if a Metamorph index or LIKE-type query is ever done on the field, then the indirect type *must* be used, or only the file name and not its contents will be searched. Even though no such queries are likely here, it's wise to use indirect anyway if that's what the column really is.)

If your input data to timport for the image is a file path, and you wish to keep that path in the table (ie. it's a permanent location), then you should be able to declare the column as indirect and timport it. If you wish to create a Texis-managed indirect (a unique file name in the indirects subdir) from your input data (ie. input is temporary), then you'll need to use <TIMPORT> in Vortex, and do the SQL insert yourself, using toind() as appropriate.
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

read .jpg files

Post by John »

In the timport schema for <TIMPORT> you would want to declare the field with the filename to be varchar, as you are just treating it as a string within Vortex.

There is no problem doing a <SQL> insert, update or delete within a <TIMPORT> loop, that's what it is there for.

SET is only used to UPDATES.
John Turnbull
Thunderstone Software
iclbloom
Posts: 103
Joined: Mon May 07, 2001 5:51 pm

read .jpg files

Post by iclbloom »

This is a sample of what I am trying to do, but I have not got it right yet :-(

Thanks
Leon Bloom


<!-- =================================================================
This function imports data from pipe-delimited files into the database
-->
<a name=fimport_tidsent export debug>

<$image_schema = "
keepfirst
trimspace
csv ,
field vfilename varchar(10) 1
field vimagecount integer 2
field vthumbnail varchar(10) 3
field vfullimage varchar(10) 4
field vcaption varchar(10) 5
">

<if $imagefile neq "">

<timport max = 3 $image_schema FROMFILE $imagefile>

<if $debug ne 0>

vfilename: $vfilename<br>
vimagecount: $vimagecount<br>
vthumbnail: $vthumbnail<br>
vfullimage: $vfullimage<br>
vcaption: $vcaption<br>
<br><br>
</if>

<sql max = 3 "insert into tidsent values(
$vfilename,
$vimagecount,
$vthumbnail,
$vfullimage,
$vcaption,
toind($vthumbnailfile),
toind($vfullimagefile)
)"></sql>
</timport>
<else>
Missing variable "imagefile" containing the filename for the image data input
</if>

</a>
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

read .jpg files

Post by John »

You probably want something like:

<a name=fimport_tidsent export debug>
<$image_schema = "
keepfirst
trimspace
csv ,
field vfilename varchar(10) 1
field vimagecount integer 2
field vthumbnail varchar(10) 3
field vfullimage varchar(10) 4
field vcaption varchar(10) 5
">

<if $imagefile neq "">
<timport max = 3 $image_schema FROMFILE $imagefile>
<if $debug ne 0>
vfilename: $vfilename<br>
vimagecount: $vimagecount<br>
vthumbnail: $vthumbnail<br>
vfullimage: $vfullimage<br>
vcaption: $vcaption<br>
<br><br>
</if>
<sql NOVARS "insert into tidsent values(
$vfilename,
$vimagecount,
$vthumbnail,
$vfullimage,
$vcaption,
toind(fromfile($vthumbnail)),
toind(fromfile($vfullimage))
)"></sql>
</timport>
<else>
Missing variable "imagefile" containing the filename for the image data input
</if>
</a>

Do you see the correct information with debug set?

If $vthumbnail and $vfullimage point to files that will stick around you can just insert those variables without the toind(). If you do want Texis to keep the data in it's own files you would need to use

toind(fromfile($vfullimage))

so that the contents of $vfullimage is read in, and then stored.
John Turnbull
Thunderstone Software
iclbloom
Posts: 103
Joined: Mon May 07, 2001 5:51 pm

read .jpg files

Post by iclbloom »

Thanks for the help, now for the last part. Kai mentioned in the second message that I can
spew the file, well I have the .jpg file in an indirect field and when I spew it,
<spew $thumbnailfile>, I get the following:

ÿØÿà?JFIF???HHÿþ-Handmade Software, Inc. Image Alchemy v1.9 ÿÛC?????????????????????????? ? ?
? ? ? ?????? ?????????ÿÀ ?P????ÿÄÒ???????????????? ?????????????}???????!1A??Qa?"q?2‘¡?#B±Á
?RÑð$3br‚ ?????%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸
¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÚ????ûïûzÚúÊÆkG¾ӕ-ã ?²Z2¾?uó`r??*1©?FŒkZҶõpLZ~å\co
ü{`ƒÏ'?¥jZxÃKÒmšÚîÊKö„–{›¿!??„Ç?.?Óêj¥ÇÄï?N?Åke?²•Sö„ 6:à?ŸÃó¨,|Km{¥Ï???Hgpcº·Ec?:˜¸?†*ô~!¶DE

That is problem #1.

what I really want to do, is use the file name path, $vthumbnailfile, in an <img> tag e.g.

<img src="$vthumbnailfile">

but when I do this is what I get:

<img src="c:\morph3\sentinel\indirects\f\a0\e5\3bc7e5af0.tmi">

which of course does not work when viewed via a browser.

Thanks
Leon Bloom
Post Reply