<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Weston Mossman on Medium]]></title>
        <description><![CDATA[Stories by Weston Mossman on Medium]]></description>
        <link>https://medium.com/@westonmossman?source=rss-db59a2601b86------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*B-yccdHGdCgjEayRbi70Lw.jpeg</url>
            <title>Stories by Weston Mossman on Medium</title>
            <link>https://medium.com/@westonmossman?source=rss-db59a2601b86------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 13:12:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@westonmossman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ColorizerJS — My first Hack project at eBay]]></title>
            <link>https://medium.com/@westonmossman/colorizerjs-my-first-hack-project-at-ebay-f971d29c0f09?source=rss-db59a2601b86------2</link>
            <guid isPermaLink="false">https://medium.com/p/f971d29c0f09</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ebay]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Weston Mossman]]></dc:creator>
            <pubDate>Fri, 22 Jul 2016 23:04:12 GMT</pubDate>
            <atom:updated>2016-07-25T23:32:44.069Z</atom:updated>
            <content:encoded><![CDATA[<h4>First blog on Medium, whooooh!</h4><p>When I open-source ColorizerJS, I will post a link to the Git repo so that you can just steal it without reading this blog post, but for now you are out of luck and will have to read this blog post.</p><p>Hello! This blog will mostly be about my project, ColorizerJS, but since this is my first post on Medium I thought I’d introduce myself. For those unaware of some of the terminology and nomenclature I will try to provide some brief short-bracket explanations[“[]”]. If you are submerged in web software or already cool enough to know the terminology, just pretend like there are no brackets.</p><p>I started working at eBay in May after graduating from UCSC with a bachelors in Computer Science Game Design (now called <a href="https://games.soe.ucsc.edu/">CGPM</a>). CSGD at UCSC was a great program for front-facing developers, as games are as much about the user (or player) as they are the algorithm. Plus, at least at UCSC, I got a whole lot more experience with managing assets and interfacing between technologies in my Game Design classes than in my vanilla CS classes.</p><p>The interview process at eBay was great, not too niche-specific, and not too broad, with great questions on both niche and broad ends of the interview spectrum. I was hired as a full-time IC [individual contributor] on the Search Front-End [abbreviated to FE, meaning closest to the client] engineering team. This means that whenever you enter a <a href="http://www.ebay.com/sch/i.html?_odkw=expensive+stuff&amp;_sop=16&amp;_osacat=0&amp;_from=R40&amp;_trksid=p2045573.m570.l1313.TR0.TRC0.H0.TRS0&amp;_nkw=expensive&amp;_sacat=0">search query</a>, the stuff you get back, Javascript [functionality, the bulk of it], CSS [look and feel], HTML [structure], is what my team handles.</p><p>I was lucky enough to be on a great team at a great time. When <a href="https://www.ebayinc.com/stories/news/its-a-wrap-ebay-innovators-shine-at-hack-week/">Hack Week 2016</a> rolled in mid-June, I was too new to have many responsibilities keeping me from joining the hack week, yet experienced enough to know our codebase a bit and have some ideas for my potential project.</p><p>After some thought I determined something that would be fun to work on, enhance the user experience, and bring in revenue to eBay through increased buyer activity. The initial problem arose from eBay sellers often having non-standard sized images, either shorter or thinner than a square. With the current redesign of Search Results Page (SRP), the method to combat this problem was to overlay all images onto a grey bounding square. This technically fixed the problem of non-standard image dimensions, but it did not lend itself to good <a href="http://i.imgur.com/IZTpcV7.png">aesthetics</a>. This is where ColorizerJS comes in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*19lLOhvYUZQEUtd49cEXKQ.png" /><figcaption>Current background implementation in production — not so hot</figcaption></figure><p>I was inspired to do ColorizerJS by my coworker (and one of my many mentors) Yoni Medoff, who made a script that drew loaded images to an HTML <a href="http://www.w3schools.com/html/html5_canvas.asp">Canvas</a>, averaged the RGB [Red Green and Blue channels. You definitely know this. These brackets are so condescending] values of each image in the search results for a query, then created an RGB color out of those average channel numbers and set the containing square (normally just white or grey) behind the image to be the average color. This was intended to provide a more visually appealing way of standardizing the size and shape of each image in search results than just slapping them on top of a grey square. Yoni’s implementation looked significantly better than just a grey square, but it could definitely be improved upon.</p><p>There were four problems with his approach:<br> 1. It did not look good in many cases. Sometimes the generated average does match any color in an image, a strong foreground color can throw that average out of whack, and most of all, the average may not resemble the ‘background’ at all.<br>2. It depended on HTML &lt;img/&gt; elements [images on the (meta)physical webpage] which limited usage to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction">DOM</a> so isomorphic [using the same code in a browser and on the server] server-side use was impossible and parallelized web-workers [<a href="http://www.w3schools.com/html/html5_webworkers.asp">MULTIPLE CPU THREADS RUNNING JS?</a>] wouldn’t work.<br>3. It converted the &lt;img/&gt; to an HTML Canvas element to extract the pixel data, a slow process that required large Canvas objects to be drawn to before being of any use. This was not time or memory efficient.<br>4. It was very tightly coupled to our codebase, meaning it could not be used in other parts of the site or on other websites without huge changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*Tooaj8C5rFQ6zJLARiv50w.png" /><figcaption>My code running average algorithm — it’s alright</figcaption></figure><p>I thought “Oh snap here’s my chance to win $10k and become VP of engineering or whatever the Hack Week prize is.” Easy! All I needed to do was come up with a way to load the image into the <a href="https://varvy.com/pagespeed/leverage-browser-caching.html">browser cache</a> to reduce double-requests [when a browser makes two requests to the server for the same image, BAD] and then read that cached image as binary[1000100101], analyze the binary file to extract its RGB pixel data, organize that in a logical way to analyze, then analyze it and determine the most likely background color of the image to be appended to the background bounding square of the image, all while keeping the analysis code modular to be used on the client, web-worker, or server, and independent of our codebase and modular so that I could open source it as an <a href="https://www.npmjs.com/">NPM module</a> to be used by anyone on any page. Mayyybe not so easy.</p><p>So now I have a considerable job, meet all these criteria in a week, but where do I start? I decided starting with a client-side [user’s browser] image decoding [decoders analyze an image and give back a string of numbers indicating the channel values of each pixel] NPM module. eBay supports JPEG and WEBP (Google’s new <a href="https://developers.google.com/speed/webp/">super great</a> image compression format) formats, and I figured since JPEG was older I’d have more luck with it, so off I went looking for a client-side decoder. There weren’t any client-side JPEG decoders. Only <a href="https://en.wikipedia.org/wiki/Node.js">Node</a>[server-side]. Nice. After a few PRs [<a href="https://yangsu.github.io/pull-request-tutorial/">Pull Request</a>] to <a href="https://github.com/eugeneware/jpeg-js">jpeg-js</a> (to support native UInt8Arrays instead of just Node specific ‘Buffer’ arrays) and just like that I had a client-side JPEG decoder. Nice.</p><p>Next I had to figure out how to request the image file as binary, and found a great article on <a href="http://api.jquery.com/jquery.ajax/">JQuery AJAX</a> <a href="http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/">custom transport overriding</a>. This allowed me to send the data to jpeg-js as a bitstream in a Javascript typed-array (UInt8Array in this case). Jpeg-js sadly only supported 4-channel (including alpha-transparency) output so in my color analysis code I handled both 3-channel and 4-channel output flags as 4-channel. This increased data overhead by about 1/3 more bytes per image [since each channel of a pixel is one bye], inconvenient but not a deal-breaker.</p><p>Jpeg-js, with my now merged pull request to support client side analysis and array type, analyzed my binary input (after some array conversion) and gave me back an object with a height, width, and array of bytes [number from 0–255], each 4 array indices corresponding to a pixel in the image binary. I found a great WEBP analysis library called <a href="http://libwebpjs.appspot.com/v0.1.2/">libwebp</a> (I got the code by viewing the page source) and got it working.</p><p>Now it’s time to do some background analysis!</p><p>I started with the simple average-of-the-edge-pixels algorithm and appended the resulting color to the bounding box behind each image result, which expectedly yielded sub-par results, but at least the analysis was working. I then I decided to up the size of the pixels analyzed to around 10 pixels per side. If the image was tall I would check the outer 8 pixels on the left and right side, if it was short I would check the top and bottom. I made a function that determined two modes for each color channel, determined the weight of each mode against each other and against the average, shaving off outliers and conversely, fully using the mode if it was significant enough in the image. This yielded great results, especially for images with fairly flat background colors or heavily dominating colors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M3wks7Hg0x6zWjbUmio1YQ.png" /><figcaption>Lookin’ pretty good</figcaption></figure><p>But some images, especially those with sporadic colors, colors that are very different from side to side, edges with very different colors than the rest of the image, borders, and other complex images sometimes did not cooperate with this implementation. Some generated colors would clearly not occur at all in the picture, or just not fit as a background.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*VXXvHB1HnRytWwOewIeUOA.png" /><figcaption>WHERE IS THAT MINT COMING FROM? — Mr Nice Guy could have fixed this if he were still here.</figcaption></figure><p>I did not want this algorithm to be just <em>KINDA</em> similar to the background for an image, I wanted it to be almost <em>EXACT. </em>I came up with a few modifications, more modes, more pixels analyzed, some analysis of sectors and their potential significance to determine their weight, and doing analysis of 2 pixels as well as large sections of 20–30 pixels from each edge and determining their weights. Also I fine tuned the cutoffs for modes and averages to be more likely to exclude an average and include a mode. Some modifications to weights for each sector was required before I came up with a fairly finished product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*RTrFc_ChmGU5gwi_zMWFSw.png" /><figcaption>Niiiiiiice. It actually looks like a background.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*SnvXZI99QQNezDe8O55R_g.png" /><figcaption>Particularly impressed with the fighter jet analysis, good job Colorizer</figcaption></figure><p>I presented the Colorizer at the end of the week of Hackweek 2016 and got some positive responses from the judges. Fun project, and some hard work for a little more than a week.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SGsiJf0Nr8pcMSSAB9amlg.png" /><figcaption>Best slide in my Hackweek demo</figcaption></figure><p>I hope to make all magic numbers into parameters that can be defined by the user to widen the range of use cases that ColorizerJS can apply to. I also want to make some more functions in the colorizer that can make it work with path image files to be used on the server, satisfying my original requirement of the module being isomorphic. If it ends up looking good, I might also come up with separate background colors for each side (top and bottom or left and right) if they are different enough. This would especially work well with unprofessionally shot images in sellers’ homes that might have vastly different upper and lower backgrounds in their images.</p><p>Soon I will get the code up and tested on Search Results Page, working with Web workers, and published as an NPM module with some examples of usage so that you and all of your friends can do some sweet image analysis. All that is needed is an image URL and the image is cached and analyzed and out comes the background color!</p><p>Thanks for reading, I will update soon with more info as the project progresses.</p><p>Big thanks to Yoni Medoff for the idea and initial implementation along with encouragement along the way, <a href="http://eugeneware.com/">Eugene Ware</a> for jpeg-js and the help getting it implemented, and <a href="https://www.linkedin.com/in/senthilpadmanabhan">Senthil Padmanabhan</a> for the inspiration to write this blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f971d29c0f09" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>