<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: �Jay </title>
    <description>The latest articles on DEV Community by �Jay  (@wisly).</description>
    <link>https://dev.to/wisly</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2108412%2F4dd0b8a1-95ff-40b6-bf96-3d1940c570c1.png</url>
      <title>DEV Community: �Jay </title>
      <link>https://dev.to/wisly</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wisly"/>
    <language>en</language>
    <item>
      <title>Why We Reserve Credits Before Running an Image Editing Job</title>
      <dc:creator>�Jay </dc:creator>
      <pubDate>Wed, 18 Nov 2026 08:33:38 +0000</pubDate>
      <link>https://dev.to/wisly/why-we-reserve-credits-before-running-an-image-editing-job-6fb</link>
      <guid>https://dev.to/wisly/why-we-reserve-credits-before-running-an-image-editing-job-6fb</guid>
      <description>&lt;p&gt;You click &lt;strong&gt;Start editing&lt;/strong&gt; and the request times out. You hit Retry. A few seconds later, the image processor reports that the job failed.&lt;/p&gt;

&lt;p&gt;That one interaction raises three questions. Did the first request create a job? Could a second request spend the same credits? What happens to the credits when the job fails?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://picviva.ai/en" rel="noopener noreferrer"&gt;PicViva&lt;/a&gt; is a product photo editor. Take a background removal job as an example: the editor can accept the request and return a task ID while the image is still processing. If the user retries before seeing that ID, the backend needs a way to recognize the original submission.&lt;/p&gt;

&lt;p&gt;A credit reservation makes those questions easier to answer. The API holds credits when it accepts a job. The worker turns that hold into a charge when the job succeeds, or releases it when the job reaches a terminal failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give a retry the same identity
&lt;/h2&gt;

&lt;p&gt;Have the client generate an idempotency key when the user submits an edit. If the response is lost, resend the request using that same key. An intentional second edit gets a fresh key, even if it uses the same image and settings.&lt;/p&gt;

&lt;p&gt;On the server, scope the key to the workspace and enforce uniqueness in the database. A lookup can handle the common case where the original request already committed. The unique constraint handles the race where two requests both pass the lookup. Resolve a duplicate to the existing task when it represents the same operation. If your API also stores a request fingerprint, it can reject reuse of the key with different parameters.&lt;/p&gt;

&lt;p&gt;The task row is the receipt. Once the API has it, the client can poll that task ID to find out what happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Put the balance check in the update
&lt;/h2&gt;

&lt;p&gt;Suppose a workspace has 10 credits, and two different jobs each ask for 7. Both requests might read an available balance of 10 before either writes. Put the check in the statement that creates the hold so it uses the current balance when the database applies the update.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;credit_accounts&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;reserved_balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reserved_balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;cost&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;workspace_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;workspace_id&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;reserved_balance&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;balance&lt;/code&gt; is the settled balance and &lt;code&gt;reserved_balance&lt;/code&gt; is the amount currently on hold. The SQL uses illustrative named parameters. For a positive-cost job with an existing account, one affected row means the reservation succeeded. In the example, the first update leaves 3 available. The other update affects zero rows because it needs 7.&lt;/p&gt;

&lt;p&gt;Create the task row and record the reservation in the same transaction. If the reservation fails, roll back the task insert too. Make the job eligible for dispatch after commit so a worker can see the task and the hold together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Close the hold when the job finishes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client          API / database                  Worker
  |-- submit --&amp;gt; create task + hold 7             |
  |              commit and make job runnable ---&amp;gt;|
  |-- retry ---&amp;gt; return the same task ID          |
  |                                               |-- process image
  |              success: charge 7, clear hold &amp;lt;--|
  |                 or                            |
  |              failure: clear hold only &amp;lt;------|
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Starting from a balance of 10 with 7 reserved, here's how the terminal outcomes differ.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;Balance&lt;/th&gt;
&lt;th&gt;On hold&lt;/th&gt;
&lt;th&gt;Available&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Task accepted&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Task succeeded&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Task failed&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last two rows are alternative outcomes from the accepted state. On success, the worker lowers both the balance and the held amount. On terminal failure, it only lowers the held amount. The available balance stays at 3 on success because those 7 credits were already unavailable while the job was running.&lt;/p&gt;

&lt;p&gt;I’d put the terminal task transition and its accounting update in one transaction. A conditional transition from the expected state gives the worker a way to tell whether this delivery is still allowed to settle the task. That matters if the worker commits a result and then loses the acknowledgement. The job may be delivered again, and a repeated completion must leave the balance alone. Keep the hold in place while an internal retry is still pending.&lt;/p&gt;

&lt;p&gt;There’s also a gap between a database commit and sending work to a separate queue. If the process dies in that gap, a committed task can sit with credits reserved and nothing running. A transactional outbox or a recovery scan for committed, undispatched tasks can close that gap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three cases to run before shipping
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lost response.&lt;/strong&gt; Submit the same key twice. Expect the same task ID and one hold.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Competing jobs.&lt;/strong&gt; Start two jobs with different keys that cost 7 each against a balance of 10. Expect one accepted task and 3 credits available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repeated completion.&lt;/strong&gt; Deliver the terminal event twice. Check that the charge or release happens once and that the persisted task status agrees with the ledger.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’ve built a job queue with prepaid credits, how do you recover holds for jobs that never reach a worker?&lt;/p&gt;

</description>
      <category>backend</category>
      <category>sql</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How We Keep Partial Translations Out of Our Next.js Sitemap</title>
      <dc:creator>�Jay </dc:creator>
      <pubDate>Wed, 18 Nov 2026 08:08:56 +0000</pubDate>
      <link>https://dev.to/wisly/how-we-keep-partial-translations-out-of-our-nextjs-sitemap-43ik</link>
      <guid>https://dev.to/wisly/how-we-keep-partial-translations-out-of-our-nextjs-sitemap-43ik</guid>
      <description>&lt;p&gt;PicViva supports 19 languages. Suppose we have a guide ready in English and Simplified Chinese, and the French translation is still a draft. Which URLs should show up in the sitemap?&lt;/p&gt;

&lt;p&gt;For this guide, I'd expect two entries. The app's language picker can tell me which languages the interface supports. To build the sitemap, I need to know which versions of this particular guide are ready for readers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Put the available languages on each article
&lt;/h2&gt;

&lt;p&gt;In PicViva, the article API returns an &lt;code&gt;availableLocales&lt;/code&gt; field along with the slug. The sitemap uses it for both blog posts and resource guides. Article page metadata reads the same field when building language alternates. That gives both outputs the same source for which translations exist.&lt;/p&gt;

&lt;p&gt;Here's an example payload with a fictional slug. The site's locale configuration also includes French, so adding French to the global configuration alone would tell us very little about this article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"slug"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"photo-export-checklist"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"availableLocales"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"zh-CN"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One detail worth deciding at the API boundary is what an empty array means. For an article feed, I'd treat it as zero eligible versions. For a route that really is available in every supported language, I'd supply the full list explicitly. PicViva's shared sitemap builder currently falls back to the site's locale list for missing or empty lists, so the article feed needs to supply a non-empty list for each included article. The standalone example below uses the stricter article-only behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build the URL rows and alternates together
&lt;/h2&gt;

&lt;p&gt;Next.js lets you return a typed array from &lt;code&gt;app/sitemap.ts&lt;/code&gt;. For each article, generate one row per eligible locale. Give each row the same map of language alternates, including a link to itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;MetadataRoute&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'next'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://example.com'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;supported&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'en'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'zh-CN'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'fr'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Article&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;availableLocales&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;articleEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Article&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MetadataRoute&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sitemap&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;eligible&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;availableLocales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;supported&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;localizedUrls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;eligible&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'/blog/'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;languages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;localizedUrls&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;languages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;en&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;languages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'x-default'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;languages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;en&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;localizedUrls&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;alternates&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;languages&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sitemap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MetadataRoute&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sitemap&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;articleEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'photo-export-checklist'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;availableLocales&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'en'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'zh-CN'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;x-default&lt;/code&gt; link gives this example a fallback for visitors whose language doesn't match an alternate. The example emits it only when English is eligible. Choose the fallback that makes sense for your site, such as a language selector or a designated default version.&lt;/p&gt;

&lt;p&gt;Here's one of the two XML entries. The second uses the Chinese URL in &lt;code&gt;&amp;lt;loc&amp;gt;&lt;/code&gt; and repeats the same three alternate links. Line breaks and indentation are for readability.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;urlset&lt;/span&gt; &lt;span class="na"&gt;xmlns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"http://www.sitemaps.org/schemas/sitemap/0.9"&lt;/span&gt;
        &lt;span class="na"&gt;xmlns:xhtml&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;url&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;loc&amp;gt;&lt;/span&gt;https://example.com/en/blog/photo-export-checklist&lt;span class="nt"&gt;&amp;lt;/loc&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;xhtml:link&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"alternate"&lt;/span&gt; &lt;span class="na"&gt;hreflang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;
      &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/en/blog/photo-export-checklist"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;xhtml:link&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"alternate"&lt;/span&gt; &lt;span class="na"&gt;hreflang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"zh-CN"&lt;/span&gt;
      &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/zh-CN/blog/photo-export-checklist"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;xhtml:link&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"alternate"&lt;/span&gt; &lt;span class="na"&gt;hreflang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"x-default"&lt;/span&gt;
      &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/en/blog/photo-export-checklist"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/url&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/urlset&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See the &lt;a href="https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap" rel="noopener noreferrer"&gt;Next.js sitemap API&lt;/a&gt; and &lt;a href="https://developers.google.com/search/docs/specialty/international/localized-versions" rel="noopener noreferrer"&gt;Google's localized versions guide&lt;/a&gt; for the serialization and reciprocal-link requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check what happens when a translation ships
&lt;/h2&gt;

&lt;p&gt;I'd test this with two versions of the same fixture. Start with English and Simplified Chinese, then add French to the article's eligible locales. In the first run, check for two sitemap rows and confirm that neither row advertises French. In the second, check that there are three rows and that every row carries the same three language alternates plus the default.&lt;/p&gt;

&lt;p&gt;Then open each URL directly. Confirm that the body is in the expected language, that the page responds successfully, and that its canonical URL and HTML alternates agree with the sitemap. A route can return HTTP 200 while rendering English fallback content, so checking status codes alone misses the distinction that got us here.&lt;/p&gt;

&lt;p&gt;If the sitemap or page is cached, repeat the checks after the release becomes visible. A mismatch right after publishing could come from the underlying content data or from the page and XML refreshing at different times. Checking both responses gives you somewhere concrete to start.&lt;/p&gt;

&lt;p&gt;When a translation goes live on your site, how do you keep its page and sitemap entry in sync?&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>seo</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why AI Photo Editing Needs More Than a Good Prompt</title>
      <dc:creator>�Jay </dc:creator>
      <pubDate>Thu, 05 Nov 2026 04:41:31 +0000</pubDate>
      <link>https://dev.to/wisly/why-ai-photo-editing-needs-more-than-a-good-prompt-3ai0</link>
      <guid>https://dev.to/wisly/why-ai-photo-editing-needs-more-than-a-good-prompt-3ai0</guid>
      <description>&lt;p&gt;A prompt can describe a convincing scene. A useful photo editor also has to preserve the parts of the image that the user never asked to change.&lt;/p&gt;

&lt;p&gt;Consider a simple request: put a ceramic mug on a different background. The background may look excellent while the handle changes shape, the glaze becomes smoother, or the small lettering drifts. The image succeeds as a composition and fails as an edit.&lt;/p&gt;

&lt;p&gt;A reliable workflow has to answer two questions: did the requested change happen, and did everything else remain acceptable?&lt;/p&gt;

&lt;h2&gt;
  
  
  Turn the request into an edit contract
&lt;/h2&gt;

&lt;p&gt;“Make this photo better” leaves too many decisions open. Separate the intended change from the constraints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change the surroundings and supporting shadow.&lt;/li&gt;
&lt;li&gt;Preserve the subject’s silhouette, color, texture, and readable text.&lt;/li&gt;
&lt;li&gt;Keep the original asset available for comparison.&lt;/li&gt;
&lt;li&gt;Deliver the requested dimensions without cutting off important details.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These constraints do not guarantee model compliance. They establish a review target. Masks can narrow the edit region, but transparent materials, thin chains, and openings still need inspection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate file validity from visual correctness
&lt;/h2&gt;

&lt;p&gt;An output can be a valid image file and still be the wrong result.&lt;/p&gt;

&lt;p&gt;File checks can establish that an image decodes, has the expected dimensions, and uses a format that supports transparency. They cannot establish that a label still says the same thing or a reflection makes physical sense.&lt;/p&gt;

&lt;p&gt;Use separate checks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Technical validity:&lt;/strong&gt; readable file, expected format and dimensions, appropriate alpha handling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edit accuracy:&lt;/strong&gt; requested changes appear in the intended region.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Subject fidelity:&lt;/strong&gt; shape, text, material, and identifying details remain acceptable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delivery quality:&lt;/strong&gt; crop, contrast, and composition work at the final display size.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Automate objective rules. Keep a side-by-side view for visual judgments. A thumbnail helps assess composition; lettering and edges need full-size inspection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three operations hiding behind “retry”
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Repeated submission:&lt;/strong&gt; the user clicks twice or a client repeats a request after losing a response. This should not accidentally create two independent paid jobs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transport retry:&lt;/strong&gt; a temporary provider condition, such as throttling, triggers a bounded retry policy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creative retry:&lt;/strong&gt; the user wants another result because the first image is unsatisfactory. This is a new decision, with its own cost and output history.&lt;/p&gt;

&lt;p&gt;These operations should not share one undifferentiated “Try again” path. A timeout does not prove that remote generation never started.&lt;/p&gt;

&lt;p&gt;A useful task-creation pattern is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;begin transaction
  find existing task by workspace and idempotency key
  if found: return existing task
  create task and reserve credits
commit
  enqueue task after commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a control-flow sketch. A production implementation also needs to handle concurrent requests and enforce the intended uniqueness in its persistence layer.&lt;/p&gt;

&lt;p&gt;Application-level idempotency does not make an external provider call exactly-once. If a provider completes work but the response is lost, blindly calling it again can still duplicate remote work. Provider request IDs, status reconciliation, and explicit uncertain states matter where supported.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the task lifecycle separate from the prompt
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://picviva.ai/en?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=beyond_prompts" rel="noopener noreferrer"&gt;PicViva&lt;/a&gt; provides a concrete implementation example: task creation includes a workspace-scoped idempotency lookup, task creation and credit reservation happen in a transaction, and queueing is deferred until after commit.&lt;/p&gt;

&lt;p&gt;Its shared external-call wrapper retries qualifying throttling failures within a configured attempt limit, using increasing waits. Other errors are propagated.&lt;/p&gt;

&lt;p&gt;Those choices address submission and accounting consistency. Visual quality remains a separate concern.&lt;/p&gt;

&lt;p&gt;The general design principle is to give each concern its own owner:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Task creation handles duplicate submissions.&lt;/li&gt;
&lt;li&gt;The provider boundary handles eligible transport failures.&lt;/li&gt;
&lt;li&gt;The review workflow handles whether a generated image is worth keeping.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Export is part of the edit
&lt;/h2&gt;

&lt;p&gt;A resize may cut through the subject. A transparent image may be flattened unexpectedly. A preview may hide that the downloaded file has different dimensions.&lt;/p&gt;

&lt;p&gt;Check the actual downloaded output. Keep crop position explicit and choose transparency deliberately. Review every channel-specific version rather than assuming one successful crop transfers to every aspect ratio.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with a small acceptance set
&lt;/h2&gt;

&lt;p&gt;Choose three inputs: a straightforward subject, one with difficult boundaries, and one with readable text or reflective material.&lt;/p&gt;

&lt;p&gt;Run the same task and record what needed correction. Count accepted outputs, retries, and review effort. Reuse this acceptance set when changing a model, prompt, or export step.&lt;/p&gt;

&lt;p&gt;The prompt remains important. The surrounding workflow makes its result inspectable, recoverable, and ready to use.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>backend</category>
      <category>architecture</category>
      <category>imageprocessing</category>
    </item>
    <item>
      <title>Why 'looks white' fails Amazon's image check — and how to test it in code</title>
      <dc:creator>�Jay </dc:creator>
      <pubDate>Tue, 03 Nov 2026 09:28:23 +0000</pubDate>
      <link>https://dev.to/wisly/why-looks-white-fails-amazons-image-check-and-how-to-test-it-in-code-3ij3</link>
      <guid>https://dev.to/wisly/why-looks-white-fails-amazons-image-check-and-how-to-test-it-in-code-3ij3</guid>
      <description>&lt;p&gt;A seller uploads a product photo on a pure white background. It looks white. Amazon rejects it.&lt;/p&gt;

&lt;p&gt;The background measured 242, 244, 246 — visually indistinguishable from 255 on a warm monitor, but far enough from the threshold to fail an automated check.&lt;/p&gt;

&lt;p&gt;This post walks through the checks we implemented for PicViva’s free compliance checker: background pixel sampling, product coverage, resolution, and overlay detection. The code is simplified for readability; production needs more edge cases.&lt;/p&gt;

&lt;p&gt;What the check actually compares&lt;/p&gt;

&lt;p&gt;Amazon’s requirements are not a style guide. The automated checks compare measurable properties:&lt;/p&gt;

&lt;p&gt;Background pixel values, per channel&lt;br&gt;
Product fill ratio inside the frame&lt;br&gt;
Overlays: text, badges, borders, watermarks&lt;br&gt;
Resolution and aspect ratio&lt;br&gt;
Category-specific rules that override the general policy&lt;/p&gt;

&lt;p&gt;The first one causes the most rejections, and it is also the easiest to test locally.&lt;/p&gt;

&lt;p&gt;Sampling the background in code&lt;/p&gt;

&lt;p&gt;The naive approach is to look at the average colour of the whole image. That fails because the product occupies the centre and drags the average away from white.&lt;/p&gt;

&lt;p&gt;Instead, sample the corners and a thin ring around the frame. Those regions should be pure background.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sharp&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"sharp"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;CORNER_SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;WHITE_MIN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;WHITE_RATIO&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.98&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;checkBackground&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sharp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#ffffff"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;resolveWithObject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;channels&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;corners&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;CORNER_SIZE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;CORNER_SIZE&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;CORNER_SIZE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;CORNER_SIZE&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;white&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;corners&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;y0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;CORNER_SIZE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;x0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;CORNER_SIZE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;channels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;WHITE_MIN&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;WHITE_MIN&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;WHITE_MIN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;white&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;whiteRatio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;white&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;pass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;white&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;WHITE_RATIO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three details matter more than the code itself:&lt;/p&gt;

&lt;p&gt;Flatten transparency first. A transparent PNG exported to JPEG gets composited onto some background. If you check the raw alpha channel, you are testing a file the marketplace will never see. Flatten onto white before sampling.&lt;/p&gt;

&lt;p&gt;Sample the corners, not the whole image. The product occupies the centre. A whole-image average tells you almost nothing.&lt;/p&gt;

&lt;p&gt;Report the actual values. A boolean “pass” is not useful to a seller. Return the minimum and maximum per channel so they can see whether they are at 254 or 242.&lt;/p&gt;

&lt;p&gt;Interpreting the result&lt;/p&gt;

&lt;p&gt;The official requirement is 255, 255, 255. In practice, JPEG compression makes exact 255 rare across an entire region.&lt;/p&gt;

&lt;p&gt;A practical rule set:&lt;/p&gt;

&lt;p&gt;Fail if the corner average on any channel is below 250.&lt;br&gt;
Warn if it is between 250 and 254 — close enough to look white, but still not exact.&lt;br&gt;
Pass if all channels are 255 across the sampled region.&lt;/p&gt;

&lt;p&gt;Do not use the product’s edge pixels. Anti-aliasing and contact shadows legitimately darken them. Sample a margin inside the frame and a thin band outside the product’s bounding box.&lt;/p&gt;

&lt;p&gt;Estimating product coverage&lt;/p&gt;

&lt;p&gt;If the image has an alpha channel, coverage is straightforward: count pixels above an alpha threshold.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;coverageFromAlpha&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;channels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;alpha&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;channels&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For JPEG, there is no alpha. The simplest approach is background subtraction: count pixels that differ from white by more than a tolerance. That over-counts shadows and props, which is why coverage should be reported as an estimate, not a verdict.&lt;/p&gt;

&lt;p&gt;The working range from our sample of roughly 200 rejection cases was 85% to 92% of the frame, with margin on all sides. Too small and too tightly cropped fail for the same underlying reason: the product does not dominate the image.&lt;/p&gt;

&lt;p&gt;Resolution and overlays&lt;/p&gt;

&lt;p&gt;Resolution is metadata:&lt;/p&gt;

&lt;p&gt;const { width, height } = await sharp(file).metadata();&lt;/p&gt;

&lt;p&gt;Overlay detection is harder. OCR catches text, but badges, borders and watermarks are often graphic. A practical first pass combines:&lt;/p&gt;

&lt;p&gt;OCR confidence above a threshold&lt;br&gt;
Edge density in regions that should be empty&lt;br&gt;
A border scan along the frame edges&lt;/p&gt;

&lt;p&gt;Treat overlay findings as warnings unless the rule is unambiguous. False positives are worse than a missed warning here.&lt;/p&gt;

&lt;p&gt;Putting it together&lt;/p&gt;

&lt;p&gt;Each check returns a finding rather than a single score:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Finding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pass"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;"warn"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;"fail"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;findings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Finding&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;findings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s2"&gt;"fail"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;findings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That shape lets the UI explain why an image is at risk, instead of showing a red X with no context.&lt;/p&gt;

&lt;p&gt;What code cannot catch&lt;/p&gt;

&lt;p&gt;Three rejection causes are procedural, not visual:&lt;/p&gt;

&lt;p&gt;“Authoritative image already exists.” On a shared ASIN, Amazon may lock a preferred image. Your upload never takes effect. Re-editing cannot fix a catalog-ownership problem.&lt;br&gt;
Byte-identical resubmission. Amazon fingerprints uploaded images. Exporting the same file again can be rejected without reprocessing.&lt;br&gt;
Category rules that override the general policy. An image can pass every general check and still fail a softlines-specific rule.&lt;/p&gt;

&lt;p&gt;A checker can flag the visual risks. It cannot guarantee approval, and it should say so.&lt;/p&gt;

&lt;p&gt;Takeaways&lt;br&gt;
Compare pixel values, not perception.&lt;br&gt;
Sample corners and edges, not the whole image.&lt;br&gt;
Flatten transparency before testing.&lt;br&gt;
Report actual values, not just pass/fail.&lt;br&gt;
Treat coverage and overlays as estimates with warnings.&lt;br&gt;
Keep procedural causes out of the visual score.&lt;/p&gt;

&lt;p&gt;PicViva’s compliance checker runs these checks for free (0 credits) against Amazon, Walmart and TikTok Shop rules: &lt;a href="https://picviva.ai/en/tools/amazon-image-compliance-checker" rel="noopener noreferrer"&gt;https://picviva.ai/en/tools/amazon-image-compliance-checker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I work on PicViva. The checker flags potential issues; it does not guarantee marketplace approval.&lt;/p&gt;

</description>
      <category>ecommerce</category>
      <category>ai</category>
      <category>imageprocessing</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
