Storing thumbnails of uploaded JPEG images

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
hopkins
Posts: 41
Joined: Wed Nov 28, 2018 11:09 am

Storing thumbnails of uploaded JPEG images

Post by hopkins » Wed Nov 28, 2018 11:36 am

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 ?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Storing thumbnails of uploaded JPEG images

Post by bogs » Wed Nov 28, 2018 12:22 pm

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?
Image

[-hh]
VIP Livecode Opensource Backer
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

Post by [-hh] » Wed Nov 28, 2018 12:57 pm

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?
Last edited by [-hh] on Wed Nov 28, 2018 4:31 pm, edited 2 times in total.
shiftLock happens

hopkins
Posts: 41
Joined: Wed Nov 28, 2018 11:09 am

Re: Storing thumbnails of uploaded JPEG images

Post by hopkins » Wed Nov 28, 2018 1:54 pm

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.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Storing thumbnails of uploaded JPEG images

Post by bogs » Wed Nov 28, 2018 3:16 pm

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]-
Image
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
The code to put it in the other images was -

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
Is that more like what you had in mind?
Image

hopkins
Posts: 41
Joined: Wed Nov 28, 2018 11:09 am

Re: Storing thumbnails of uploaded JPEG images

Post by hopkins » Wed Nov 28, 2018 4:22 pm

Thanks - this is what I want to do and will try "export" as well.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”