Storing thumbnails of uploaded JPEG images
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Storing thumbnails of uploaded JPEG images
Hello,
I am writing an application to browse through a music collection. Each album has a JPEG image file which I would like to store as a "thumb nail" (reduced size) in an SQLite database.
In order to convert the image to a smaller size, I have created two invisible images in my stack, with fixed positions:
- the filename of the first image is set to the filename of the file
- If I then try to get the text of the image, it is always returned empty
- so I copied the imagedata of the first image to the second one, and then get the text of the second image
set the filename of image tPath
get the imagedata of image "image1"
set the imagedata of image "image2" to it
put the text of image "image2" into tImage
Seems like there could be a simpler way of doing this, without having to copy the "imagedata" from one image to another. Any suggestions ?
I am writing an application to browse through a music collection. Each album has a JPEG image file which I would like to store as a "thumb nail" (reduced size) in an SQLite database.
In order to convert the image to a smaller size, I have created two invisible images in my stack, with fixed positions:
- the filename of the first image is set to the filename of the file
- If I then try to get the text of the image, it is always returned empty
- so I copied the imagedata of the first image to the second one, and then get the text of the second image
set the filename of image tPath
get the imagedata of image "image1"
set the imagedata of image "image2" to it
put the text of image "image2" into tImage
Seems like there could be a simpler way of doing this, without having to copy the "imagedata" from one image to another. Any suggestions ?
Re: Storing thumbnails of uploaded JPEG images
I'm sure I'm overlooking something, but why not skip the first image and put the file directly into the thumbnail sized image, then work from there?
Alternately, load both images from the same file if one is for display, lets say, and the other is for reducing the size?
Alternately, load both images from the same file if one is for display, lets say, and the other is for reducing the size?
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Storing thumbnails of uploaded JPEG images
0. if there is no img "thumb1" then create img "thumb1"
1. put url("binfile:"&filePath) into img "thumb1"
2. set rect of img "thumb1" to (0,0,desiredWidth,desiredHeight)
3. set imagedata of img "thumb1" to the imagedata of img "thumb1"
step 3 makes the new size permanent (and changes the fileLength of img "thumb1").
@bogs
He probably wants the thumbnails for faster loading and using less memory?
1. put url("binfile:"&filePath) into img "thumb1"
2. set rect of img "thumb1" to (0,0,desiredWidth,desiredHeight)
3. set imagedata of img "thumb1" to the imagedata of img "thumb1"
step 3 makes the new size permanent (and changes the fileLength of img "thumb1").
@bogs
He probably wants the thumbnails for faster loading and using less memory?
Last edited by [-hh] on Wed Nov 28, 2018 4:31 pm, edited 2 times in total.
shiftLock happens
Re: Storing thumbnails of uploaded JPEG images
Thanks - I get an error "unknown chunk", but I assume I missed declaring tImage ? Does tImage have to contain the name of an existing image ?
Anyway, copying imagedata works (using one of the defined images), so that is simpler.
Thanks.
To answer your question, I save the thumbnails to accelerate the display.
Anyway, copying imagedata works (using one of the defined images), so that is simpler.
Thanks.
To answer your question, I save the thumbnails to accelerate the display.
Re: Storing thumbnails of uploaded JPEG images
Ah, I see. Well, to answer your original question then, I wonder if something like this wouldn't work (although -hh's answer would probably be better).
If I got the original question right, your looking to put one image loaded into an image control into a smaller or different size image control, like this [the image from file is on the right, images one to four are taken from that one]-
The code for loading the file that I used was -
The code to put it in the other images was -
Is that more like what you had in mind?
If I got the original question right, your looking to put one image loaded into an image control into a smaller or different size image control, like this [the image from file is on the right, images one to four are taken from that one]-
The code for loading the file that I used was -
Code: Select all
on mouseUp
answer files "Select the image you wish to view:" with type ("Image files|jpg,jpeg,JPEG,JFIF,png")
if the result is not "" then
set the fileName of image "imgOriginal" to it
# next line is necessary because images are essentially
# empty of information other than imageData...
export image "imgOriginal" to image "imgOriginal"
else
end if
end mouseUp
Code: Select all
on mouseUp
put the text of image "imgOriginal" into image "imgOne"
// could just as easily come after the export line in the code above...
end mouseUp
Re: Storing thumbnails of uploaded JPEG images
Thanks - this is what I want to do and will try "export" as well.