<?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 waynelu on Medium]]></title>
        <description><![CDATA[Stories by waynelu on Medium]]></description>
        <link>https://medium.com/@luyongfugx?source=rss-d4eba30ba286------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*G-oIihfoaNlttV1E</url>
            <title>Stories by waynelu on Medium</title>
            <link>https://medium.com/@luyongfugx?source=rss-d4eba30ba286------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 07:43:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luyongfugx/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[Use pure dart to read the camera stream image(nv1/brga8888) data]]></title>
            <link>https://medium.com/@luyongfugx/use-pure-dart-to-read-the-camera-stream-image-nv1-brga8888-data-8b991216a511?source=rss-d4eba30ba286------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b991216a511</guid>
            <dc:creator><![CDATA[waynelu]]></dc:creator>
            <pubDate>Fri, 26 Apr 2024 06:03:17 GMT</pubDate>
            <atom:updated>2024-04-26T06:03:57.247Z</atom:updated>
            <content:encoded><![CDATA[<p>those days, i start a side project: <a href="https://t.co/LsDroeDopJ">TimeGps Camera</a> , a app that can add time and location info to the picture that you take from your camera.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MYW7l1yxKzcOXZDRBzQg6w.jpeg" /></figure><p>in this project , i use the <a href="https://pub.dev/packages/camera">https://pub.dev/packages/camera</a> camera package to take picture, and than add some info on the picture. i use a feature that can read the stream image from the camera like this:</p><pre>await cameraController.startImageStream((CameraImage image) {<br>  _processCameraImage(image);<br>}).onError((error, stackTrace) {<br>  print(error);<br>})</pre><p>and the _processCameraImage function can get a CameraImage instance, it is a object that contain the byte data of a image. you can use those data to generate a image. but i found that in the community have no a good example for how to decode this data to a jpg or a png.</p><p>after some research and tries, i finally get the mothod:</p><ol><li>first, you have to set the image formart in ios/android before you call the startImageStream, here is the code :</li></ol><pre>ImageFormatGroup controllerFormat = ImageFormatGroup.jpeg;<br><br>  controllerFormat =<br>    Platform.isIOS ? ImageFormatGroup.bgra8888 : ImageFormatGroup.nv21;<br><br>final CameraController cameraController = CameraController(<br>    cameraDescription, currentResolutionPreset,<br>    imageFormatGroup: controllerFormat, enableAudio: false);</pre><p>2.then you can use those code to decode the image data:</p><p>2.1 ios:</p><pre>static imglib.Image convertBGRA8888ToImage(CameraImage cameraImage) {<br>  final plane = cameraImage.planes[0];<br><br>  return imglib.Image.fromBytes(<br>    width: cameraImage.width,<br>    height: cameraImage.height,<br>    bytes: plane.bytes.buffer,<br>    rowStride: plane.bytesPerRow,<br>    bytesOffset: 28,<br>    order: imglib.ChannelOrder.bgra,<br>  );<br>}</pre><p>2.2 android:</p><pre>static Future&lt;imglib.Image&gt; convertYUV420ToImage(CameraImage cameraImage,int rotation) async {<br>  final imageWidth = cameraImage.width;<br>  final imageHeight = cameraImage.height;<br><br>  final yBuffer = cameraImage.planes[0].bytes;<br>  final uBuffer = cameraImage.planes[1].bytes;<br>  final vBuffer = cameraImage.planes[2].bytes;<br><br>  final int yRowStride = cameraImage.planes[0].bytesPerRow;<br>  final int yPixelStride = cameraImage.planes[0].bytesPerPixel!;<br><br>  final int uvRowStride = cameraImage.planes[1].bytesPerRow;<br>  final int uvPixelStride = cameraImage.planes[1].bytesPerPixel!;<br><br><br><br><br><br>// if (rotation == null) return null;<br><br><br>  final image = imglib.Image(width: imageWidth, height: imageHeight);<br><br>  for (int h = 0; h &lt; imageHeight; h++) {<br>    int uvh = (h / 2).floor();<br><br>    for (int w = 0; w &lt; imageWidth; w++) {<br>      int uvw = (w / 2).floor();<br><br>      final yIndex = (h * yRowStride) + (w * yPixelStride);<br><br>      // Y plane should have positive values belonging to [0...255]<br>      final int y = yBuffer[yIndex];<br><br>      // U/V Values are subsampled i.e. each pixel in U/V chanel in a<br>      // YUV_420 image act as chroma value for 4 neighbouring pixels<br>      final int uvIndex = (uvh * uvRowStride) + (uvw * uvPixelStride);<br><br>      // U/V values ideally fall under [-0.5, 0.5] range. To fit them into<br>      // [0, 255] range they are scaled up and centered to 128.<br>      // Operation below brings U/V values to [-128, 127].<br>      final int u = uBuffer[uvIndex];<br>      final int v = vBuffer[uvIndex];<br><br>      // Compute RGB values per formula above.<br>      int r = (y + v * 1436 / 1024 - 179).round();<br>      int g = (y - u * 46549 / 131072 + 44 - v * 93604 / 131072 + 91).round();<br>      int b = (y + u * 1814 / 1024 - 227).round();<br><br>      r = r.clamp(0, 255);<br>      g = g.clamp(0, 255);<br>      b = b.clamp(0, 255);<br><br>      image.setPixelRgb(w, h, r, g, b);<br>    }<br>  }<br>  var image2 = imglib.copyRotate(image, angle: rotation);<br>  return image2;<br>}</pre><p>the imglib class is the image package,you can import it like this:</p><pre>import &#39;package:image/image.dart&#39; as imglib;</pre><p>before this, you have to add the image package in your pubspec.yaml file</p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  image: ^4.1.7</pre><p>in android there is issue that you should correct the rotation of the picture, you can get the rotation from the camera like this:</p><pre>final sensorOrientation = camera.sensorOrientation;<br>if (camera.lensDirection == CameraLensDirection.front) {<br>  rotationCompensation =<br>      (sensorOrientation + rotationCompensation) % 360;<br>} else {<br>  rotationCompensation =<br>      (sensorOrientation - rotationCompensation + 360) % 360;<br>}</pre><p>but , use pure dart to process the data is very slow, i don’t suggest you read data by dart, you can do this job in native code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b991216a511" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[how to add watermark on a image by nextjs]]></title>
            <link>https://medium.com/@luyongfugx/how-to-add-watermark-on-a-image-by-nextjs-b24b5c8d6ff7?source=rss-d4eba30ba286------2</link>
            <guid isPermaLink="false">https://medium.com/p/b24b5c8d6ff7</guid>
            <category><![CDATA[watermark]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[sharp]]></category>
            <dc:creator><![CDATA[waynelu]]></dc:creator>
            <pubDate>Fri, 13 Oct 2023 08:43:06 GMT</pubDate>
            <atom:updated>2023-10-13T08:43:06.173Z</atom:updated>
            <content:encoded><![CDATA[<p>two days ago, i decided to add watermark on the image generated by my side project aigf.art . and this feature is published today. and i want to share the method to add watermark on a image this article.</p><p>solutions:</p><ol><li>add watermark in browser</li></ol><p>when i want to do this job, i think the best way to add watermark on a image is use canvas in the browser and after my research , i found some libaries for this work. and i decide to use :<a href="https://github.com/zhensherlock/watermark-js-plus">https://github.com/zhensherlock/watermark-js-plus</a> .</p><p>watermark-js-plus is base on the canvas , they do the work on browser. i think it is a good choice for me because my project is a free project on vercel. work in browser is low cost. but went i start to code, i found that it is not good as i thought. first it must manipulate the dom, but my project is an react app, everything is Virtual Dom, manipulate dom is like a hacker way. and if you do this job in browser you should get the image from network,and user can get the original image without watermark, so i give up this method. but i have to said that watermark-js-plus is a very good project.hope some day i will use it.</p><p>2. add watermark on serverside</p><p>do this work on serverside is easy, you just to find a node libary to do this job. and i found this project:<a href="https://github.com/lovell/sharp">https://github.com/lovell/sharp</a></p><p>and somethings you have to notice is that the size of the watermark image and the size of the original image. and how to draw a txt on a image, sharp provide a composite method to do this job. i use this method to merge two image，and here is my code:</p><p>import sharp from “sharp”;</p><p>export const getWaterMarkImageByTxt = async (</p><p>width: number,</p><p>height: number,</p><p>txt: string</p><p>) =&gt; {</p><p>// const width = 400;</p><p>// const height = 200;</p><p>// const text = “https://www.aigf.art&quot;;</p><p>// const svg = `</p><p>// &lt;svg width=”${width}” height=”${height}”&gt;</p><p>// &lt;rect x=”0&quot; y=”0&quot; width=”100%” height=”100%” fill=”#fff” /&gt;</p><p>// &lt;text x=”50%” y=”50%” text-anchor=”middle” fill=”#000&quot;&gt;${txt}&lt;/text&gt;</p><p>// &lt;/svg&gt;</p><p>// `;</p><p>const svg = `</p><p>&lt;svg width=”${width}” height=”${height}”&gt;</p><p>&lt;text x=”50%” y=”50%” text-anchor=”middle” font-weight=”bold” font-family=”Helvetica, Arial, sans-serif” font-size=”36&quot; id=”svg_1&quot; stroke-width=”0&quot; stroke=”#000&quot; fill=”#2bbc4f”&gt;${txt}&lt;/text&gt;</p><p>&lt;/svg&gt;</p><p>`;</p><p>return sharp(Buffer.from(svg));</p><p>};</p><p>export const getWaterMarkImageByText = async (</p><p>picUrl: string,</p><p>markTxt: string = “aigf.art”,</p><p>width: number = 400,</p><p>height: number = 200</p><p>) =&gt; {</p><p>const fimg = await fetch(picUrl);</p><p>const imageBuffer = await (await fimg.blob()).arrayBuffer();</p><p>const orgImg = sharp(imageBuffer);</p><p>const metadata = await orgImg.metadata();</p><p>width = metadata.width! &lt; width ? metadata.width! : width;</p><p>height = metadata.height! &lt; height ? metadata.height! : height;</p><p>const watermask = await (</p><p>await getWaterMarkImageByTxt(width, height, markTxt)</p><p>).toBuffer();</p><p>let top = metadata.height! — height;</p><p>top = top &lt;= 0 ? 20 : top;</p><p>let left = (metadata.width! — width) / 2;</p><p>left = left &lt;= 0 ? 20 : left;</p><p>const output = await orgImg</p><p>.composite([{ input: watermask, left: left, top: top }])</p><p>.png()</p><p>.toBuffer();</p><p>const base64 = “data:image/jpeg;base64,” + output.toString(“base64”);</p><p>return base64;</p><p>};</p><p>you can call: await getWaterMarkImageByText(picUrl); to get a base64 code</p><p>that’s all, i hope this article can help you</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b24b5c8d6ff7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[improve some feature today for aigf.art]]></title>
            <link>https://medium.com/@luyongfugx/improve-some-feature-today-for-aigf-art-488099587923?source=rss-d4eba30ba286------2</link>
            <guid isPermaLink="false">https://medium.com/p/488099587923</guid>
            <category><![CDATA[ai-art-generator]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[waynelu]]></dc:creator>
            <pubDate>Wed, 11 Oct 2023 01:37:14 GMT</pubDate>
            <atom:updated>2023-10-11T01:37:14.208Z</atom:updated>
            <content:encoded><![CDATA[<p>after one day of promotion, <a href="https://www.aigf.art/en">aigf.art</a> get 20 visitor, and 3 sign up among them.</p><p>and i now struggle in how to do next. eventually, i decide to do some improvment today</p><h3>user can upload his/her own poster picture(target picture)</h3><p>when i promote <a href="https://www.aigf.art/en">https://www.aigf.art/en</a>, i found maybe it is a promote way that i swap some user’s picture on X or Ins, and send them the result , they might want to use it. but when i want to do this, i found that there is no way to do it . i think our users may have the same problem.</p><p><strong>give not paid people a chance to generate 2 pictures(but with a watermark of </strong><a href="https://www.aigf.art/en"><strong>https://www.aigf.art</strong></a><strong> ) , if they like , they can would pay.</strong></p><p>I found that some people sign in and want to generate a pictures to look the result, but they stop. i think that maybe they just lazy to pay, if they found the result is good, they may pay. and if they don’t pay, they may want to share the result picture, so add a wartemark of <a href="https://www.aigf.art/en"><strong>https://www.aigf.art</strong></a><strong> is a good way to get more user</strong></p><p>so let me do it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=488099587923" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[the result of my first promotion post for my ai side project]]></title>
            <link>https://medium.com/@luyongfugx/the-result-of-my-first-promotion-post-for-my-ai-side-project-3583126345b5?source=rss-d4eba30ba286------2</link>
            <guid isPermaLink="false">https://medium.com/p/3583126345b5</guid>
            <category><![CDATA[promotion]]></category>
            <category><![CDATA[ai-art-generator]]></category>
            <category><![CDATA[ai-art]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[waynelu]]></dc:creator>
            <pubDate>Mon, 09 Oct 2023 23:13:15 GMT</pubDate>
            <atom:updated>2023-10-09T23:13:15.600Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I finish my first side project, a aiart generate online tool: <a href="https://www.aigf.art/">https://www.aigf.art</a></p><p>A<a href="https://www.aigf.art/">ig</a>f is a web tool that can create poster picture by your own selfile. in this project, i import movies,tvshows,actor or actress posters picture from fmdb by its api. you can easily upload a selfile of yourown,search and select the poster your like from fmdb, click a button to create some mv/tv style posters of you. and here is some examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*43G8uS84ccb3i1ZJ" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/0*n5JoIriGwA6gGvak" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*aBCPeDS15OZIgMlO" /></figure><p>I think the result is perfect enough.</p><p>And then i need to promote my project,after some research, i decide to post my first article on <a href="https://www.reddit.com/">https://www.reddit.com/</a> because i found that this website is so hot, and many people like to talk about everything including airt on it. i search some reddit comunities and join in.and then i post my aritcle on a comunity named r/stablediffusion, it’s url is <a href="https://www.reddit.com/r/StableDiffusion/">https://www.reddit.com/r/StableDiffusion/</a> and here is my post :<a href="https://www.reddit.com/r/StableDiffusion/comments/173tc6s/one_photo_to_create_a_poster_of_your_own/">https://www.reddit.com/r/StableDiffusion/comments/173tc6s/one_photo_to_create_a_poster_of_your_own/</a></p><p>After one night, my post was read by 1000 people, and 7 among them click the url to my wesite,but no one register as a user of my project,here is some picture of the data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3xvOFjWsL6ZfQ872dwXsQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*zjnJj0cd0dvDZvGDSOVX0Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*WC_sEj_blWOgPYMPpX_LtA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*lymwwZQr-bvCkGNalx5gmA.jpeg" /></figure><p>i feel a little dispointed, but this result is still not very bad. now i will figure out 2 things:</p><ol><li>why only 7 people go to my website while 1000 people have been read my post?</li><li>why no one register to my website while 7 people come?</li></ol><p>If somebody can give me some advises, please let me know, i will very appreciated, and my twritter:<a href="https://twitter.com/luyongfugx">https://twitter.com/luyongfugx</a></p><p>And i will also share the experiences about my works to promote my side project, 3q!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3583126345b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>