Announcement

Collapse
No announcement yet.

Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

    Are you looking for an array of all the generated images for a specific image?

    For example, if you have the foreach

    <mvt:foreach iterator="image" array="toolkitadditionalimages">
    <img src="&mvt:global:imageroot;&mvte:image:image:image ;">
    </mvt:foreach>

    Assume I create a new function, you would change line two to
    <mvt:item name="toolkit" param="generatedimages|l.all_settings:image:image: id" />
    which would generate a subarray like
    <mvt:foreach iterator="generatedimage" array="generatedimages">
    <img src="&mvt:global:imageroot;&mvte:image:image:image ;">
    </foreach>
    that could be used inside the main foreach loop.

    That would list all of the images for that main image. So then how would you know which one to display?
    Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
    Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
    Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
    Facebook http://www.facebook.com/EmporiumPlus
    Twitter http://twitter.com/emporiumplus

    Comment


      #17
      Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

      So assume:

      The Product has 4 Images added to Additional Images.

      The Product Image Dimensions creates 4 'sizes' { Original, Main, Closeup, Thumb } if enabled to do so for main and closeup, with original being unmodified direct upload copy.

      Out of the 4 Images added to Additional Images 1 has to be set to a 'Featured' type or some other type, otherwise default to the first returned for failsafe.

      That 'Featured' type then has 4 sizes, of which would also have to be requested in the code using size types above.

      Now I'm not good at writing toolkit code but here would be my logic in psuedo ruby style:

      Code:
      # Get All Images for a product
      prod_images = Product.images
      
      # Loop through all Images Array
      prod_images.each do | image | 
          # If Image is of given type in this case 'featured'
          if image.type == 'featured'
              # Get Images related thumbnail url
              <img src="#{image.thumbnail.url}" />
          end
      end
      This is making an assumption that some things existed as far as relationships between the image and the generated images, which after a quick look at the DB it doesn't contain... unfortunately.

      If a GeneratedImage table had an identifier such as {Original, Main, Closeup, Thumb} this would be much easier.

      It seems that you would actually have to test the height and width of all returned images to grab the smallest combination to "assume" the thumbnail. However I dont feel like that is a very good solution. Technically you could set your closeup image smaller then your thumbnail image thus then making your logic assumption wrong. That is user error at this point in my opinion, but still is a point of concern.

      Obviously now seeing that there is something missing in order to make this happen (unless I am missing a join table somewhere which I may be), it gets a bit more difficult as it would require a change made to core miva db. I would have assumed that the relationships of the auto sized images would have been recorded, in addition to the generated height and widths.

      In my opinion the table GeneratedImages should have the following columns:

      Code:
      id, image_id, type, width, height, image
      where as type = {original, main, closeup, thumb} considering they are identified as such in the selections under the Product Display Layout Image Dimensions tab already.

      SQL would be:

      Code:
      Select * FROM Images as prodimg INNER JOIN GeneratedImages as genimg ON prodimg.id = genimg.image_id WHERE genimg.type = 'thumb' WHERE prodimg = {id queried};
      Steven Spriggs
      Web Developer
      ktm-parts.com

      Comment


        #18
        Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

        You correctly identified why I asked the question above "So then how would you know which one to display?".

        It has generated the images based on what you configured in the dimensions tab of the image machine. I suppose if the page had not yet been displayed, the generated images do not yet exist for that product. It seems that one of the sizes does match as the aspect ratio would often make it so the other size did not. I didn't analyze the file's date that close so cannot be sure on that. You could probably test for the width or height to match the value on either side of the "x" but that might not always work either. So if you set the size to be 274 by 274 you cold look for 274 in the image file name.
        Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
        Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
        Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
        Facebook http://www.facebook.com/EmporiumPlus
        Twitter http://twitter.com/emporiumplus

        Comment


          #19
          Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

          Originally posted by wcw View Post
          I suppose if the page had not yet been displayed, the generated images do not yet exist for that product.
          This is something that I find odd to begin with. Why wouldn't you want to auto size the image on upload rather then on product page load, seems like backwards UX? If I actively upload an image I am wanting it to auto thumbnail / resize. I don't understand the practicality behind the implementation, again assumptions this probably has to do with product imports and other ways to add images, just seems wrong from my familiarity level with miva core code as a whole.

          Again the catch here would be to return the full image marked 'featured' and hope the developer that created the site template handles images bigger then the view block using css ( .thumbnail > img { display: block; max-width: 100%;}

          Originally posted by wcw View Post
          So if you set the size to be 274 by 274 you cold look for 274 in the image file name.

          I am also assuming this is the best way... but again assuming you create the new function in toolkit right?



          ...Now that we fleshed that out, should we report a missing need attribute on generatedimages table to miva core? It only seems like this could be useful in a bunch of different spots.
          Steven Spriggs
          Web Developer
          ktm-parts.com

          Comment


            #20
            Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

            The problem with a field name in the generatedimages is that things like thumbnail vary from page to page. On the CTGY it might be 150x150 and on the PROD it might be 42x42. Then there are mobile which may be smaller. I think that is why the name is not used in that table. I could probably add a 5th and 6th param to the customimage function (width and height or is it height and width). When looking at the dimensions input which do you thing is width (the first or second input)?
            Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
            Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
            Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
            Facebook http://www.facebook.com/EmporiumPlus
            Twitter http://twitter.com/emporiumplus

            Comment


              #21
              Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

              The reason we don't process them all on upload, is if someone uploaded 50,000 photos, they would easily tie up server resources for an extended period as opposed to generating them the initial time they're needed.
              Thanks,

              Rick Wilson
              CEO
              Miva, Inc.
              [email protected]
              https://www.miva.com

              Comment


                #22
                Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                Originally posted by wcw View Post
                The problem with a field name in the generatedimages is that things like thumbnail vary from page to page. On the CTGY it might be 150x150 and on the PROD it might be 42x42. Then there are mobile which may be smaller. I think that is why the name is not used in that table. I could probably add a 5th and 6th param to the customimage function (width and height or is it height and width). When looking at the dimensions input which do you thing is width (the first or second input)?
                Ok I hadn't thought about the differences between CTGY and PROD pages. I hadn't gotten that far into the redesign. I guess I assumed there was only 4 available sizes and that was shared per page. Personally I would like the functionality to work with preset defaults across all pages, maybe customizable per store instead, but I can live with that.

                I think going off width would be best for me, as most images are going to be horizontal in aspect. But your prolly better off with having both params, then offering a a place holder that causes it not to check that aspect? e.g. |170|x for checking width or |x|170 for checking height.
                Steven Spriggs
                Web Developer
                ktm-parts.com

                Comment


                  #23
                  Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                  Originally posted by Rick Wilson View Post
                  The reason we don't process them all on upload, is if someone uploaded 50,000 photos, they would easily tie up server resources for an extended period as opposed to generating them the initial time they're needed.
                  Rick that was what I figured after some thought on it and multiple ways of uploading images like via product import.

                  Would be interesting to see if there wasn't a way to batch process the uploaded images to reduce server resources instead after a product image import. I can definitely see why the decision was made coming from a site that does a lot of product imports and a huge number of products.
                  Steven Spriggs
                  Web Developer
                  ktm-parts.com

                  Comment


                    #24
                    Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                    Because there could be multiple image sizes defined you have to consider both width and height. You still might end up with more than one image for a specific type that meets the criteria. But something like (width equal to and height less than or equal to) OR (height equal to and width less than or equal to) would yield an acceptable images. If the image type is specified, that would narrow it down even further.
                    Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
                    Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
                    Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
                    Facebook http://www.facebook.com/EmporiumPlus
                    Twitter http://twitter.com/emporiumplus

                    Comment


                      #25
                      Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                      I have to chime in an salute Miva for choosing not to do it upon upload. I"ve done the thumbnail on the fly thing in php and even married it to miva merchant before image machine was on the planning boards.

                      I started out doing resize upon upload of the main big image mostly becuase it was easier to program and I"M all about lazy.
                      But ended up going to resizing when the web visitor viewed the image. if the resized/target image didn't exist then I get the original big image and do the resize and make a physical file. I ended up doing this for many reasons. One as Rick pointed out, it's much less server cpu usage to do it only when they are needed rather than all at once. But also, I found if I needed to replace/update/repair images that it made it really easy to get rid of all those resized old images... I merely had to delete them. IF customers were still accessing them.. then they'd be regenerated automatically. But if they truely were obsolete images.. it was easy peasy to get rid of them without accidentaly wiping out images I needed to keep. It was a quick way to recover hard drive space, clean up old files. And if I have to move a website to a new server... I don't have to copy every image file which can take forever. I know I left out some reaons... but THANK YOU MIVA for building this in finally!

                      Comment


                        #26
                        Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                        We are likely going to add a Utility that you could click to trigger all of processing, but then you could choose to put your store in Maintenance mode and control when it happens. There are times when you need to control when it's done, but doing it on Import isn't that time.
                        Thanks,

                        Rick Wilson
                        CEO
                        Miva, Inc.
                        [email protected]
                        https://www.miva.com

                        Comment


                          #27
                          Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                          Originally posted by ZER0KTM View Post
                          will it ever be?

                          can you add it?

                          To me it doesn't seem like this is a stretch to ask, it's something that seems fundamentally basic.

                          I would assume it would be fairly easy to grab the data from the image id and join it with data from the GeneratedImages table, add in the join for ImageTypes and you should be able to grab all resized images, and filter by 'type' if wanted.
                          I can add it. Is it worth the steep update charge of $10 (less discounts and coupons)?

                          It would use additional parameters in the token. If they were there it would look at generated images. If it found a match it would use it. If you turn on the fallback parameter, it would use the base image if no generated image existed. It could also be filtered by image type.
                          Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
                          Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
                          Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
                          Facebook http://www.facebook.com/EmporiumPlus
                          Twitter http://twitter.com/emporiumplus

                          Comment


                            #28
                            Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                            Originally posted by wcw View Post
                            i can add it. Is it worth the steep update charge of $10 (less discounts and coupons)?
                            yes
                            Mark Hood
                            Vermont Gear

                            Comment


                              #29
                              Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                              Damn, two people want that feature. ;-O
                              Last edited by wcw; 06-22-12, 06:22 AM.
                              Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
                              Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
                              Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
                              Facebook http://www.facebook.com/EmporiumPlus
                              Twitter http://twitter.com/emporiumplus

                              Comment


                                #30
                                Re: Pulling Product Image Custom Fields (Image Machine) within a Toolkit subcat Funct

                                Originally posted by wcw View Post
                                I can add it. Is it worth the steep update charge of $10 (less discounts and coupons)?

                                It would use additional parameters in the token. If they were there it would look at generated images. If it found a match it would use it. If you turn on the fallback parameter, it would use the base image if no generated image existed. It could also be filtered by image type.
                                WHOOA now watch that higher figure, your gonna put me in the poor house! :P

                                yeah sounds great!
                                Steven Spriggs
                                Web Developer
                                ktm-parts.com

                                Comment

                                Working...
                                X