<?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: WeryAI</title>
    <description>The latest articles on DEV Community by WeryAI (@weryai-team).</description>
    <link>https://dev.to/weryai-team</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%2F4196015%2F32ead68b-a66a-47b2-bee2-0ae264b9b4a2.jpg</url>
      <title>DEV Community: WeryAI</title>
      <link>https://dev.to/weryai-team</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/weryai-team"/>
    <language>en</language>
    <item>
      <title>Testing a Japanese Name Generator Without Mistaking Suggestions for Verified Names</title>
      <dc:creator>WeryAI</dc:creator>
      <pubDate>Tue, 03 Nov 2026 06:28:33 +0000</pubDate>
      <link>https://dev.to/weryai-team/testing-a-japanese-name-generator-without-mistaking-suggestions-for-verified-names-27fo</link>
      <guid>https://dev.to/weryai-team/testing-a-japanese-name-generator-without-mistaking-suggestions-for-verified-names-27fo</guid>
      <description>&lt;p&gt;Wery AI's brand team wrote this article with AI support.&lt;/p&gt;

&lt;p&gt;A Japanese name suggestion can be useful for a fictional character and still be a poor application fixture. A developer may accidentally treat a pleasant explanation as a verified reading, strip meaningful text while cleaning a field, or assume every name fits the same family-name structure. Before putting generated suggestions into a demo, separate two questions: does the application handle the text correctly, and has a suitable reviewer checked the name itself?&lt;/p&gt;

&lt;h2&gt;
  
  
  Define what your application actually needs
&lt;/h2&gt;

&lt;p&gt;Start with the display contract. Does the interface show a full written name, a reading, a romanized form, or a short explanatory note? Keep these as separate fields in your own fixture. A single display string is convenient for a mockup, but it can hide assumptions that later become difficult to change. For example, a search input and a printed character card may need different information.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://www.wery.ai/en/@Wery-Manager-AI-Expert-Workspace/japanese-name-generator" rel="noopener noreferrer"&gt;Wery AI&lt;/a&gt; page describes suggestions with kanji, kana, romaji, meaning notes, and reasons for fit. Those are useful categories for a manual review sheet. If you copy a candidate into a local fixture, label the source and the review status yourself. Do not build an integration around an undocumented object shape that merely looks plausible.&lt;/p&gt;

&lt;p&gt;Write down what the fixture is for as well. Testing a fictional cast list is different from validating a real person's name. This workflow is for handling text in a prototype.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the source text and your comparison form separate
&lt;/h2&gt;

&lt;p&gt;A common mistake is to clean a string once and overwrite the original. That makes it difficult to explain why a saved display value differs from the text a reviewer approved. Keep the original value available, and derive a comparison key only for the operation that needs one. A normalization choice is a technical decision, not a linguistic judgment.&lt;/p&gt;

&lt;p&gt;Unicode's &lt;a href="https://www.unicode.org/reports/tr15/" rel="noopener noreferrer"&gt;normalization specification&lt;/a&gt; explains the normalization forms. For a small illustrative test, JavaScript can compare a composed kana character with a base character followed by a combining mark. The example below tests equivalence after NFC normalization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;composed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;が&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decomposed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;が&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;equalAfterNfc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;composed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NFC&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;decomposed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NFC&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;equalAfterNfc&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;composed&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;decomposed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use a narrowly named helper if you adopt this idea. A function called normalizeEverything invites unrelated transformations. A comparison function should make clear whether it changes case, whitespace, punctuation, or Unicode representation. Review those decisions against your product's purpose instead of stacking them together because a test passes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build fixtures around behaviors, not invented naming rules
&lt;/h2&gt;

&lt;p&gt;Create a small table of cases before adding a large cast of generated candidates. Include a reading that uses combining marks, an intentionally blank optional note, a long explanation, and text containing punctuation that your renderer must display safely. Mark each fixture as synthetic. These cases can reveal layout and storage defects without claiming that the sample text is a recommended name.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Case&lt;/th&gt;
&lt;th&gt;What to check&lt;/th&gt;
&lt;th&gt;What it does not establish&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Equivalent Unicode sequences&lt;/td&gt;
&lt;td&gt;Your chosen comparison behavior&lt;/td&gt;
&lt;td&gt;A correct name reading&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Missing optional explanation&lt;/td&gt;
&lt;td&gt;The empty-state presentation&lt;/td&gt;
&lt;td&gt;That an omitted field is always optional&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Long meaning note&lt;/td&gt;
&lt;td&gt;Wrapping and reading order&lt;/td&gt;
&lt;td&gt;The truth of the explanation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Punctuation in a note&lt;/td&gt;
&lt;td&gt;Safe text rendering&lt;/td&gt;
&lt;td&gt;Permission to render arbitrary HTML&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For a manual candidate, record the written form, reading, romanization, explanation, and the person who reviewed it. A blank reviewer field should remain visible as a missing prerequisite. Do not replace it with an automated confidence label that no one has defined.&lt;/p&gt;

&lt;h2&gt;
  
  
  Review the actual component, not just the string
&lt;/h2&gt;

&lt;p&gt;Put the fixture into the component at the width people will use. Check whether kana wraps awkwardly, whether a meaning note pushes the action button out of view, and whether a screen reader encounters the label before the value. A string can survive a round trip through storage while the interface still makes it hard to understand.&lt;/p&gt;

&lt;p&gt;A short review sequence is enough to start:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Paste the original candidate into the local fixture without silently rewriting it.&lt;/li&gt;
&lt;li&gt;Verify that saving and loading retain the intended display value.&lt;/li&gt;
&lt;li&gt;Exercise the exact search or comparison operation your app supports.&lt;/li&gt;
&lt;li&gt;Review the narrow layout with a long note and a missing optional value.&lt;/li&gt;
&lt;li&gt;Ask a suitable language reviewer to check the candidate before public use.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keep a failed technical check separate from a failed content review. If the renderer truncates a reading, repair the renderer. If the reading is unverified, keep the content status unverified. Combining the two into one green check makes both problems harder to see.&lt;/p&gt;

&lt;h2&gt;
  
  
  Leave a useful handoff for the next reviewer
&lt;/h2&gt;

&lt;p&gt;A compact handoff can contain the fixture's purpose, its source, the transformations applied for comparison, and the unresolved questions. It should also say which parts were only tested locally. Do not describe a pasted candidate as a live API integration, and do not call a normalization assertion a test of the generator's cultural accuracy.&lt;/p&gt;

&lt;p&gt;The next step is to choose one component and one synthetic fixture that stresses its display behavior. Once that works, bring in a manually reviewed candidate. Keeping technical correctness and name review separate lets the prototype move forward without turning an unverified suggestion into a product rule.&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>testing</category>
    </item>
    <item>
      <title>How we built a browser image compressor that never makes files bigger</title>
      <dc:creator>WeryAI</dc:creator>
      <pubDate>Tue, 20 Oct 2026 11:05:55 +0000</pubDate>
      <link>https://dev.to/weryai-team/how-we-built-a-browser-image-compressor-that-never-makes-files-bigger-355j</link>
      <guid>https://dev.to/weryai-team/how-we-built-a-browser-image-compressor-that-never-makes-files-bigger-355j</guid>
      <description>&lt;p&gt;Choosing a JPEG quality value is easy. Keeping a promise about the downloaded file takes more work.&lt;/p&gt;

&lt;p&gt;Our compressor accepts a batch, starts processing immediately, and returns either a smaller encoding or the original file. That last option matters: an image that has already been optimized should not become larger because someone ran it through another tool.&lt;/p&gt;

&lt;p&gt;The implementation is plain JavaScript: canvas encoders, a bounded Web Worker pool, and JSZip for batch downloads. The same compression engine runs in a website and a Manifest V3 Chrome extension. Here are the decisions and failure cases behind it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Keep the compression path on the device
&lt;/h2&gt;

&lt;p&gt;For this utility, a server would add an upload, a second copy of the image, and another failure boundary. Browser APIs can already decode common image formats and encode a canvas. We keep the selected files as File and Blob objects and generate downloads from their results.&lt;/p&gt;

&lt;p&gt;Once the application and its bundled assets have loaded, the JPG, PNG, and WebP compression path does not need a network request. That is a runtime property, not a promise that an uncached page can always be opened offline.&lt;/p&gt;

&lt;p&gt;There are two exceptions worth separating. The website loads a pinned HEIC decoder when someone first imports HEIC; that request fetches decoder code, not the image. The extension also has a separate, explicit AI editing action that passes the selected image to an external editor. Neither action is part of ordinary local compression. The extension does not bundle the HEIC decoder.&lt;/p&gt;

&lt;p&gt;Keeping those boundaries explicit made the privacy explanation easier to check against the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Treat an encoding as a candidate
&lt;/h2&gt;

&lt;p&gt;We decode the input with createImageBitmap, draw it at the requested dimensions, and ask a canvas encoder for an output Blob. The core prefers OffscreenCanvas; its alternative creates an HTML canvas. Encoding uses convertToBlob when available and toBlob otherwise.&lt;/p&gt;

&lt;p&gt;The automatic format policy is small enough to read in full:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;candidateTypes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;srcType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;alpha&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;format&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="nx"&gt;format&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;format&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;auto&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;format&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="nx"&gt;srcType&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;alpha&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/webp&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/webp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/jpeg&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;srcType&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/webp&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/webp&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/jpeg&lt;/span&gt;&lt;span class="dl"&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;An opaque PNG gets WebP and JPEG candidates, and the smaller encoded Blob wins. A transparent PNG gets a WebP candidate instead of silently flattening its background. WebP stays WebP in automatic mode; JPEG follows the JPEG path. An explicitly selected output format overrides this candidate list.&lt;/p&gt;

&lt;p&gt;PNG output is also available explicitly, but a JPEG-style quality parameter is not a useful control for its lossless encoder. We do not pretend that one quality slider has equivalent behavior across formats.&lt;/p&gt;

&lt;p&gt;Before choosing candidates, the core checks every alpha value in relevant inputs. Sampling looked attractive until a fixture with one transparent pixel exposed the problem: missing that pixel could send a transparent image down the opaque JPEG path. The complete scan costs work, but it gives the format policy reliable information.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Compare against the real original
&lt;/h2&gt;

&lt;p&gt;The size guarantee belongs after candidate selection. It must also apply after resizing, forced conversion, and preprocessing.&lt;/p&gt;

&lt;p&gt;This is the actual return guard in the engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;best&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&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="na"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;originalType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;originalWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;originalHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;kept&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="na"&gt;constraintsSkipped&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resized&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;forced&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;original&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;targetMet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;targetKB&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;targetKB&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&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;Equal size counts as a reason to keep the original too. The result describes the file that will actually be downloaded, including its original dimensions and type.&lt;/p&gt;

&lt;p&gt;This choice has a visible consequence. If a requested JPEG conversion or resize would produce more bytes, the user receives the original and an “Original kept” explanation. The tool cannot promise both “always convert to this format” and “never increase file size” for every input. We give the size rule priority and expose skipped constraints.&lt;/p&gt;

&lt;p&gt;HEIC needed an additional correction. Its decoded JPEG is an intermediate, not the user's original. The wrapper passes the original HEIC file into the engine, so the final comparison uses those original bytes. Comparing only with the decoded JPEG would make the displayed savings misleading.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Bound the workers, then package the results
&lt;/h2&gt;

&lt;p&gt;Each worker receives a file, options, and a job identifier. It returns either the result or an error carrying that identifier. The UI owns the queue and file rows.&lt;/p&gt;

&lt;p&gt;The pool size is deliberately bounded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&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="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hardwareConcurrency&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&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="k"&gt;try&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;var&lt;/span&gt; &lt;span class="nx"&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;w&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;workerUrl&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;busy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pool&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That creates two to four workers rather than one per selected file. A free slot takes the next queued item. Completion updates its row, releases the slot, and pumps the queue again. When workers are unavailable, or the app is opened through file://, the code uses the main-thread path instead.&lt;/p&gt;

&lt;p&gt;Moving pixel work off the UI thread helps responsiveness; it does not remove memory limits. A compressed file can decode into a much larger pixel buffer, and transparency checks read those pixels. Large batches still depend on the device.&lt;/p&gt;

&lt;p&gt;Completed results are collected into a ZIP with the bundled JSZip library. Duplicate output names receive suffixes rather than overwriting each other. A single result downloads directly. A failed file remains an error row, instead of becoming a zero-byte “successful” download.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Reuse the engine in a Chrome extension
&lt;/h2&gt;

&lt;p&gt;The extension opens the same compressor UI in a tab. Its right-click compression action passes the selected image URL to that tab; it does not compress inside the service worker.&lt;/p&gt;

&lt;p&gt;Reading a remote image requires more care than reading a local File. The compression page initially shows an internal icon instead of loading the remote thumbnail immediately. Only after the user clicks “Compress it” does it request access to the source site and fetch the image. A denied request leaves an explanation and a manual-file alternative.&lt;/p&gt;

&lt;p&gt;The current MV3 package also declares scripting and a fixed host permission for &lt;code&gt;www.wery.ai&lt;/code&gt;. Those support the separate “Edit photo with AI” action, which places the chosen image into the editor's file input. They are not a hidden requirement of local canvas compression. Ordinary AI links only navigate; the explicit right-click editing action carries the image.&lt;/p&gt;

&lt;p&gt;Theme selection is independent of both paths. Auto follows the browser's color preference; Light and Dark set an explicit document theme. A local preference survives refresh. The website continues to follow the browser automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Test the promise, not just a nice photograph
&lt;/h2&gt;

&lt;p&gt;Our project notes record an earlier five-image website run with a 56% reduction in combined file size. That is one input set, not a general compression ratio or a speed benchmark.&lt;/p&gt;

&lt;p&gt;The screenshot below shows a different five-image batch with an 80% aggregate reduction. Its numbers should not be substituted for the earlier run.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5mzv4kjwisodj2bgjnok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5mzv4kjwisodj2bgjnok.png" alt="A separate five-image batch in the extension, with individual output formats and a ZIP download button" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For regression checks, the more useful inputs were the awkward ones. A 70-byte PNG returned unchanged. A transparent PNG with a single transparent pixel retained that pixel. A 24,163-byte HEIC returned as the original when the candidate was larger. An 85-byte PNG forced toward JPEG with smaller dimensions also returned its original bytes and dimensions.&lt;/p&gt;

&lt;p&gt;Those cases catch failures that a large, easily compressed photo misses. We also unpacked the downloaded ZIP and compared retained originals byte for byte.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2y3jlr7zlg2l5it0a00u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2y3jlr7zlg2l5it0a00u.png" alt="The before-and-after viewer for one image in the separate screenshot batch" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The comparison viewer helps inspect visual tradeoffs. It is not evidence that a lossy re-encode is pixel-identical to its input.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Leave the limits visible
&lt;/h2&gt;

&lt;p&gt;A target size is an attempt, not a guarantee. For JPEG and WebP targets, the implementation tries seven quality values per round and up to six rounds of progressively smaller dimensions. If that bounded search still misses the requested size, the result says “Target not reached.” The final original-size guard still applies.&lt;/p&gt;

&lt;p&gt;Canvas re-encoding is also not an archival, metadata-preserving operation. Animated input becomes a still image, supported encoders depend on the browser, and large canvases can run into device limits. We keep error states and retained-original states distinct from successful conversions.&lt;/p&gt;

&lt;p&gt;The most useful design decision was making the final byte comparison the authority. Format heuristics can improve, and encoders can change, while the downloaded result still obeys the same rule.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/WeryAIExpertTeam/browser-image-toolkit" rel="noopener noreferrer"&gt;source code is on GitHub&lt;/a&gt;, and the &lt;a href="https://weryaiexpertteam.github.io/browser-image-toolkit/" rel="noopener noreferrer"&gt;browser version is available here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I work on WeryAI, where we also build AI photo tools such as the &lt;a href="https://www.wery.ai/en/@Zeny-Design-AI-Expert-Workspace/ai-photo-editor?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=image_toolkit" rel="noopener noreferrer"&gt;AI photo editor&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This article was prepared with AI assistance and checked against the implementation and the project's recorded tests.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>opensource</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
