Fetching images gallery of 1 product in Commerce.js - commerce.js

Please, tell me how can i fetch all images of 1 individual product in commerce js. Cant find anything in documentation.
So, i have a single product, but instead of uploading just 1 photo, I uploaded 20.
I can only get the very first photo to be displayed. Is there a way to list all 20? There must be a way since commercejs allows more than 1 photo to be uploaded there [thats images of my product][1]
Thanks!
[1]: https://i.stack.imgur.com/Z0eZA.png

You can use the assets list on a product object, see docs here: https://commercejs.com/docs/api/#get-product. You could filter them by is_image if you have other assets attached that aren't images.
const productImages = product.assets.filter((asset) => asset.is_image)
The image object only returns the main image, whereas assets will return the rest.

Related

Exporting images in an image collection from GEE

Please I would like to know the best way to export image bands from an Image Collection in Google Earth Engine for use on my local machine. The image collection contains 21 elements which I would like to export as single image bands or an image composite of all 21 elements. How do I go about this please. Below is a code extract I have written. Thanks
var S1_1 = ee.ImageCollection('COPERNICUS/S1_GRD')
.filterBounds(SA)
.filterDate('2016-10-01', '2017-06-01')
.filterMetadata('transmitterReceiverPolarisation', 'equals', ['VV', 'VH'])
.filterMetadata('resolution_meters', 'equals' , 10);
You may want to see this answer which shows you how to turn an image collection into a single band image. From there, use Export.image.toDrive().

meteorjs help navybits:pagination

navybits:pagination is a very good package to paginate data from personalized queries to the collection, I would like to use it in my projects, but i have 2 problems:
How can you increase the number of documents per page, by default it shows only 5?
How can you change the quantity and customize the nav- pagination buttons, by default it only shows 3 to 5, plus previous and next ??
I commented on the blog, but I have not had an answer.
If someone knows some other package to paginate data, in which I can make a personalized query to the collection, and then I can paginate an array of objects, let me know.
Thank you
Article: https://blog.navybits.com/efficient-and-high-performance-pagination-in-meteor-bb5d379d234
Demo: https://meteor.navybits.com/comments
Github: https://github.com/Navybits/meteor-pagination
I had the same problem using this package, I solve it overwriting the function onCreated for "navybitsPagination" template.
Template.navybitsPagination.onCreated(function() {
You need to change this line...
//setting the amount of data we want to render in each page
this.perPage = new ReactiveVar(Number(self.data.perPage) || 10);
You should find all the code on the Github repo of the package.
I hope it helps you.

Unable to retrieve data from website with multiple pages

I could really use some help regarding a problem I'm facing. I have a project where I'm supposed to fetch the names and prices of some products. I must retrieve data from the first 5 pages of a given category.I'm trying to implement it using R, the rvest package and the SelectorGadget extension to choose the appropriate css selectors. I've written a function to do that:
readDataProject2<-function(){
url<-readline(prompt="Enter url: ")
nameTags<-readline(prompt="Enter name tags: ")
priceTags<-readline(prompt="Enter price tags: ")
itemNames<-read_html(url)%>%html_nodes(nameTags)%>%html_text()
itemPrices<-read_html(url)%>%html_nodes(priceTags)%>%html_text()
itemPrices<-itemPrices[-c(1,2)]
page<-cbind(itemNames,itemPrices)
}
and here's the page anesishome.gr. From this specific page I can go to the next etc to fetch a total of...240 products. But even when I provide the url for the next page, second page, I keep getting the data of the first page. Needless to say that choosing the option to present 240 in one single page didn't do any good. Can anybody point me to what I'm doing wrong?

Check how many pages are included in a multi-page image file with GraphicsMagick

Is there a way to determine in advance how many pages are included in a multi page tif image with GraphicsMagick ?
I know I can select the first page in this way : image.tif[0], and probably iterating the array until the command fail will return the last image, but I don't think this is the best approach.
You can get a numbered list of the pages with
gm identify image.tif
and look at the last line, or count the lines. The images are numbered 0 thru N -1.
It is not too late to answer.
I think it is not possible to get the page count beforehand, not even with libtiff.
However, you can avoid the trial and error by using Magick::readImages:
// Magick++
std::vector<Magic::Image> images;
Magick::readImages(&images, "multipage.tif");

Create new JPG image thumbnail if original file has changed

I have a simple PHP script using imagecreatefromjpeg to create a thumbnail version of original and save it to a new folder. To speed parsing (all done in the back end prior to upload to static site) I am using file_exist before the creation to check it exists and show - if not create new and show. This works fine but if the original image changes the script does not generate as the thumbnail image exists in it's old form.
I guess I need to use MD5 test but as a n00b not sure how to test if the resulting thumbnail version would be different from the existing as produced by the main image.
Current Logic:
if thumb exist == do nothing,
if thumb does not exist == create it
Additional logic
if thumb will change due to change in original == create it,
if thumb will stay the same == do nothing
The existing PHP is very poor and clobbered together so happy for any pointers from a fresh (expert) view.
Thanks, John
You want to check the time the file was modified.
http://php.net/manual/en/function.filemtime.php
if the original file's timestamp is newer than the thumbnail's timestamp, then make a new thumbnail.
Thanks guys - not sure if that will work if the original image was created previously but only just being used eg stock images that are on file elsewhere and then dragged into the /images/ folder to replace existing image but with the same filename.. does the timestamp show the date dragged or when it was created?
If you move the files, the modified timestamp does not change.
If you copy the files, the copies are created by the copy action.
When you create a file, its Date Modified timestamp is the same as its Date Created timestamp.
So if your drag is copying the files, then the modified timestamp is the timestamp of the moment that the files were copied.
It should be enough to compare the last modification date of the thumb and the original image. if the original image is newer than the thumb, you should recreate it.
In simple terms, say we have an image that is a 200x200 image filled with red and only red (so yeah a red square). We create 80x80 thumbnails. If the original image changes but is still just the same red filled square, the thumbnail will not change.
The thing is that in order to detect this you will need to create the thumbnail or apply advanced image comparison techniques, that you may as well save it.
You can however use MD5 to create a one-on-one map from original to thumbnail, by naming the thumbnails as the MD5 hash of the original. The drawback of this approach is that you will need a way to remove unused thumbnails when their originals are no longer used.
To use this approach use something like:
<?php
$thumbname = md5_file($bigimage_path);
if( !file_exists("images/thumbs/$thumbname.jpg") )
{
create_thumb($bigimage_path, $thumbname);
}
?>
This will accomplish that if you have the exact same big image as different filenames, they will all map to the same thumbnail.

Resources