www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Library for image editing and text insertion

reply Alexander Zhirov <azhirov1991 gmail.com> writes:
It is necessary to write a utility that will insert (x,y) text on 
the image. It is desirable that the utility does not depend on 
large libraries, since a minimum utility size is required. I'm 
looking for something similar in C/C++, I can't find anything. 
Maybe there is some simple library on D?
Apr 26 2022
next sibling parent reply Guillaume Piolat <first.last gmail.com> writes:
On Tuesday, 26 April 2022 at 17:22:54 UTC, Alexander Zhirov wrote:
 It is necessary to write a utility that will insert (x,y) text 
 on the image. It is desirable that the utility does not depend 
 on large libraries, since a minimum utility size is required. 
 I'm looking for something similar in C/C++, I can't find 
 anything. Maybe there is some simple library on D?
You can eventually use dplug:graphics for that https://u.pcloud.link/publink/show?code=XZPwMFVZW9c6bTWtevRvNz7UdfOOqVYIE5uk
Apr 26 2022
parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Tuesday, 26 April 2022 at 18:12:55 UTC, Guillaume Piolat wrote:
 You can eventually use dplug:graphics for that
 https://u.pcloud.link/publink/show?code=XZPwMFVZW9c6bTWtevRvNz7UdfOOqVYIE5uk
```d Performing "debug" build using /usr/bin/dmd for x86_64. intel-intrinsics 1.9.2: target for configuration "library" is up to date. dplug:core 12.5.2: target for configuration "library" is up to date. dplug:math 12.5.2: target for configuration "library" is up to date. dplug:graphics 12.5.2: building configuration "library"... /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1972,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 7)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1973,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 6 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1974,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 5 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1975,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 4 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1976,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 3 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1977,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 2 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1978,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 1 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1979,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1981,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 7)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1982,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 6 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1983,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 5 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1984,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 4 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1985,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 3 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1986,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 2 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1987,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 1 & 1)` of type `int` to `ubyte` /usr/bin/dmd failed with exit code 1. ``` It's strange, for some reason it's not building.
Apr 26 2022
parent reply Guillaume Piolat <first.last gmail.com> writes:
On Tuesday, 26 April 2022 at 20:26:42 UTC, Alexander Zhirov wrote:
 
 build error
Curious as to what DMD you are using on what OS? It builds with 2.095.1 to 2.100-b1 here.
Apr 26 2022
parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Tuesday, 26 April 2022 at 20:37:28 UTC, Guillaume Piolat wrote:
 Curious as to what DMD you are using on what OS? It builds with 
 2.095.1 to 2.100-b1 here.
DMD64 D Compiler v2.098.0 OS Solus Linux
Apr 26 2022
parent reply Guillaume Piolat <first.last gmail.com> writes:
On Tuesday, 26 April 2022 at 20:45:16 UTC, Alexander Zhirov wrote:
 On Tuesday, 26 April 2022 at 20:37:28 UTC, Guillaume Piolat 
 wrote:
 Curious as to what DMD you are using on what OS? It builds 
 with 2.095.1 to 2.100-b1 here.
DMD64 D Compiler v2.098.0 OS Solus Linux
Well I cannot reproduce your problem => https://imgur.com/a/HZvZWr2 Perhaps a DUB mismatch that would give different DIP flags. DUB version 1.27.0, built on Oct 19 2021 Good luck.
Apr 26 2022
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
To get the commands dub used, use -v.

$ dub build -v
Apr 26 2022
parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Tuesday, 26 April 2022 at 21:04:17 UTC, rikki cattermole wrote:

 $ dub build -v
```d Using dub registry url 'https://code.dlang.org/' Refreshing local packages (refresh existing: true)... Looking for local package map at /var/lib/dub/packages/local-packages.json Looking for local package map at /home/alexander/.dub/packages/local-packages.json Looking for local package map at /mnt/hdd_data/programming/d/write text on image/.dub/packages/local-packages.json Note: Failed to determine version of package lol at .. Assuming ~master. Refreshing local packages (refresh existing: false)... Looking for local package map at /var/lib/dub/packages/local-packages.json Looking for local package map at /home/alexander/.dub/packages/local-packages.json Looking for local package map at /mnt/hdd_data/programming/d/write text on image/.dub/packages/local-packages.json Found dependency dplug:graphics 12.5.2 Found dependency intel-intrinsics 1.9.2 Found dependency dplug:math 12.5.2 Found dependency dplug:core 12.5.2 Refreshing local packages (refresh existing: false)... Looking for local package map at /var/lib/dub/packages/local-packages.json Looking for local package map at /home/alexander/.dub/packages/local-packages.json Looking for local package map at /mnt/hdd_data/programming/d/write text on image/.dub/packages/local-packages.json Found dependency dplug:graphics 12.5.2 Found dependency intel-intrinsics 1.9.2 Found dependency dplug:math 12.5.2 Found dependency dplug:core 12.5.2 Generating using build Configuring dependent lol, deps:"dplug:graphics" Configuring dependent dplug:graphics, deps:"dplug:core", "dplug:math", "intel-intrinsics" Configuring dependent dplug:core, deps:"intel-intrinsics" Configuring dependent intel-intrinsics, deps: Configuring dependent dplug:math, deps:"intel-intrinsics" Performing "debug" build using /usr/bin/dmd for x86_64. intel-intrinsics 1.9.2: target for configuration "library" is up to date. Using existing build in /home/alexander/.dub/packages/intel-intrinsics-1.9.2/intel-intrinsics/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-67C75DB793DA1F77431FDBF6F478D1AC/. Copying target from /home/alexander/.dub/packages/intel-intrinsics-1.9.2/intel-intrinsics/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-67C75DB793DA1F77431FDBF6F478D1AC/l bintel-intrinsics.a to /home/alexander/.dub/packages/intel-intrinsics-1.9.2/intel-intrinsics dplug:core 12.5.2: target for configuration "library" is up to date. Using existing build in /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-D8C57FD168AF1371806144D918242E73/. Copying target from /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-D8C57FD168AF1371806144D91824 E73/libdplug_core.a to /home/alexander/.dub/packages/dplug-12.5.2/dplug dplug:math 12.5.2: target for configuration "library" is up to date. Using existing build in /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-331F3B3983F69B80C64AABFDF7D43329/. Copying target from /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-331F3B3983F69B80C64AABFDF7D4 329/libdplug_math.a to /home/alexander/.dub/packages/dplug-12.5.2/dplug Target '/home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-566711123C5A86FF62721CA5E0A67A56/ ibdplug_graphics.a' doesn't exist, need rebuild. dplug:graphics 12.5.2: building configuration "library"... /usr/bin/dmd -lib -of/home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-566711123C5A86FF62721CA5E0A67A56 libdplug_graphics.a -debug -g -w -version=Have_dplug_graphics -version=Have_dplug_core -version=Have_dplug_math -version=Have_intel_intrinsics -I/home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics -I/home/alexander/.dub/packages/dplug-12.5.2/dplug/core -I/home/alexander/.dub/packages/intel-intrinsics-1.9.2/intel-intrinsics/source -I/home/alexander/.dub/packages/dplug-12.5.2/dplug/math /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dp ug/graphics/color.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/d lug/graphics/draw.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dpl g/graphics/drawex.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/d lug/graphics/font.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dp ug/graphics/image.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug graphics/jpegload.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dpl g/graphics/mipmap.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplu /graphics/package.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplu /graphics/pngload.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplu /graphics/resizer.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphic /stb_image_resize.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphi s/stb_image_write.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/gra hics/stb_truetype.d /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/d lug/graphics/view.d -vcolumns /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1972,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 7)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1973,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 6 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1974,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 5 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1975,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 4 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1976,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 3 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1977,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 2 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1978,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 1 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1979,34): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1981,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 7)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1982,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 6 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1983,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 5 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1984,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 4 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1985,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 3 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1986,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 2 & 1)` of type `int` to `ubyte` /home/alexander/.dub/packages/dplug-12.5.2/dplug/graphics/dplug/graphics pngload.d(1987,41): Error: cannot implicitly convert expression `cast(int)scale * (cast(int)*in_ >> 1 & 1)` of type `int` to `ubyte` FAIL /home/alexander/.dub/packages/dplug-12.5.2/dplug/.dub/build/library-debug-linux.posix-x86_64-dmd_v2.098.0-566711123C5A8 FF62721CA5E0A67A56/ dplug_graphics staticLibrary /usr/bin/dmd failed with exit code 1. ```
Apr 26 2022
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
No args added there.

https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/pngload.d#L1972

Yup that code certainly looks wrong.

Note the casts above it in around:
https://github.com/AuburnSounds/Dplug/blob/master/graphics/dplug/graphics/pngload.d#L1956

So yeah upstream issue.
Apr 26 2022
prev sibling parent reply Guillaume Piolat <first.last gmail.com> writes:
On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote:
 more build errors
If you "dub upgrade" it should work a bit better. No success in reproducing the bug here.
Apr 26 2022
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 27/04/2022 9:39 AM, Guillaume Piolat wrote:
 On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote:
 more build errors
If you "dub upgrade" it should work a bit better. No success in reproducing the bug here.
It definitely on your end. void main() { int scale; int* in_ = new int; ubyte b = cast(int)scale * (cast(int)*in_ >> 7); } onlineapp.d(5): Error: cannot implicitly convert expression `scale * (*in_ >> 7)` of type `int` to `ubyte`
Apr 26 2022
parent reply Guillaume Piolat <first.last gmail.com> writes:
On Tuesday, 26 April 2022 at 21:44:56 UTC, rikki cattermole wrote:
 On 27/04/2022 9:39 AM, Guillaume Piolat wrote:
 On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov 
 wrote:
 more build errors
If you "dub upgrade" it should work a bit better. No success in reproducing the bug here.
It definitely on your end. void main() { int scale; int* in_ = new int; ubyte b = cast(int)scale * (cast(int)*in_ >> 7); } onlineapp.d(5): Error: cannot implicitly convert expression `scale * (*in_ >> 7)` of type `int` to `ubyte`
No. Obviously VRP works differently for me and for him, for an unknown reason.
Apr 26 2022
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 27/04/2022 9:55 AM, Guillaume Piolat wrote:
 On Tuesday, 26 April 2022 at 21:44:56 UTC, rikki cattermole wrote:
 On 27/04/2022 9:39 AM, Guillaume Piolat wrote:
 On Tuesday, 26 April 2022 at 21:13:38 UTC, Alexander Zhirov wrote:
 more build errors
If you "dub upgrade" it should work a bit better. No success in reproducing the bug here.
It definitely on your end. void main() {     int scale;     int* in_ = new int;     ubyte b = cast(int)scale * (cast(int)*in_ >> 7); } onlineapp.d(5): Error: cannot implicitly convert expression `scale * (*in_ >> 7)` of type `int` to `ubyte`
No. Obviously VRP works differently for me and for him, for an unknown reason.
I copied and pasted the same code that is failing from the file in question and put it into that test code. Putting an int into a ubyte absolutely should error, that is a lossy conversion and should not be automatic.
Apr 26 2022
parent reply Guillaume Piolat <first.last gmail.com> writes:
On Tuesday, 26 April 2022 at 21:59:39 UTC, rikki cattermole wrote:
 Putting an int into a ubyte absolutely should error, that is a 
 lossy conversion and should not be automatic.
It's just VRP, here it works in 2.094 https://d.godbolt.org/z/vjq7xsMdn because the compiler wasn't complaining I wouldn't know it was reliant on VRP (which is certainly an issue to be fixed).
Apr 26 2022
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 27/04/2022 10:05 AM, Guillaume Piolat wrote:
 On Tuesday, 26 April 2022 at 21:59:39 UTC, rikki cattermole wrote:
 Putting an int into a ubyte absolutely should error, that is a lossy 
 conversion and should not be automatic.
It's just VRP, here it works in 2.094 https://d.godbolt.org/z/vjq7xsMdn because the compiler wasn't complaining I wouldn't know it was reliant on VRP (which is certainly an issue to be fixed).
Okay further testing locally, I cannot reproduce. Of course I still don't think that code is right and should have the casts. Either way whatever the dmd is, it must not be as recent as thought to be.
Apr 26 2022
parent Guillaume Piolat <first.last gmail.com> writes:
On Tuesday, 26 April 2022 at 22:16:15 UTC, rikki cattermole wrote:
 Of course I still don't think that code is right and should 
 have the casts.
Absolutely. I'm a bit anxious about "accidental VRP" now, not sure if the checks fluctuate from version to version, or worse, depends upon the platform.
Apr 26 2022
prev sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Apr 26, 2022 at 05:22:54PM +0000, Alexander Zhirov via
Digitalmars-d-learn wrote:
 It is necessary to write a utility that will insert (x,y) text on the
 image.  It is desirable that the utility does not depend on large
 libraries, since a minimum utility size is required. I'm looking for
 something similar in C/C++, I can't find anything. Maybe there is some
 simple library on D?
Maybe use imagemagick? https://stackoverflow.com/questions/23236898/add-text-on-image-at-specific-point-using-imagemagick Handling multiple image formats is generally a complex task that requires multiple libraries, some of which may not be trivial. Unless you have a specific image format in mind? Also, text rendering, in general, is an extremely complex and hairy problem. At the very minimum, you need a font. If you have a bitmap font, then it's relatively easy (just blit the characters you need onto the image with alpha blending). But if you're looking at TTF fonts or similar, you're looking at the very minimum at using libfreetype to be able to meaningfully use the font file. Then there's the issue of font layout, which is language-specific and may require a complex layout engine like HarfBuzz (which requires libraries with complex dependencies). If utility size is of utmost importance, then the ideal case would be a fixed image format (so only 1 library is needed to process files of that type) with a bitmapped font (at worst, a 2nd library for reading the font) for a specific language (so no cross-language layout issues that requires complex layout engines). Then you can just treat the font characters as bitmaps and alpha-blend them onto the image. Preferably, use a monospaced bitmap font so that you can just use a fixed grid for character placement, and not have to deal with complex font metrics, hinting, kerning, and all of that complex stuff. For this, maybe look at Adam Ruppe's arsd library (https://github.com/adamdruppe/arsd) for some lightweight modules that read common image formats and do some primitive image manipulations. T -- People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird. -- D. Knuth
Apr 26 2022
parent reply Adam Ruppe <destructionator gmail.com> writes:
On Tuesday, 26 April 2022 at 18:31:49 UTC, H. S. Teoh wrote:
 maybe look at Adam Ruppe's arsd library 
 (https://github.com/adamdruppe/arsd) for some lightweight 
 modules that read common image formats and do some primitive 
 image manipulations.
I don't actually have an image to image blit function, but writing one is trivial - just loop over it and call alphaBlend. It can load ttf fonts, render them to bitmaps, load images, combined them, then save images. Can even load ttfs off the operating system if you wanted to use those.... or even have the OS functions do the drawing instead of diy, but probably easier to diy this simple case. Sample code would be: --- import arsd.image; import arsd.ttf; void main() { auto image = loadImageFromFile("/home/me/small-clouds.png"); if(image is null) throw new Exception("Couldn't load the image file"); auto tci = image.getAsTrueColorImage(); // convert to rgba for simplicity import std.file; auto font = TtfFont(cast(ubyte[]) std.file.read("/home/me/arsd/sans-serif.ttf")); int width, height; auto bitmap = font.renderString("Hello", 14, width, height); // it populates width and height fyi // where we want to put it int xput = 30; int yput = 20; int bitmapOffset = 0; // color to draw the text int r = 255; int g = 0; int b = 0; foreach(y; 0 .. height) { if(y + yput >= image.height) break; foreach(x; 0 .. width) { scope(exit) bitmapOffset++; // always advance this as long as we're still drawing... // but don't draw out of bounds if(x + xput >= image.width) continue; // replace a pixel with the blended version of the text bitmap image.setPixel( xput + x, yput + y, image.getPixel(xput + x, yput + y). alphaBlend(Color(r, g, b, bitmap[bitmapOffset])) ); } } import arsd.png; writePng("text-image.png", image); // save it back to a png } --- Open the text-image.png to see the result. (Or: --- import arsd.simpledisplay; displayImage(Image.fromMemoryImage(image)); --- to display it in a window right from your program!) My libs are available as individual files from the github - you might just use png instead of the whole image.d to avoid needing additional files for formats you don't need - or you can pull it on dub under the arsd-official:image_files package and arsd-official:ttf.
Apr 26 2022
next sibling parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote:

 Sample code would be:
Ego have problems cum scribendarum hic quoque, fortasse opus est dare aliquid aliud, cum componendis? ```d ~/programming/d/pic $ dmd app.d /usr/bin/ld: app.o:(.data.rel.ro+0x10): undefined reference «_D4arsd5image12__ModuleInfoZ» /usr/bin/ld: app.o:(.data.rel.ro+0x30): undefined reference «_D4arsd3png12__ModuleInfoZ» /usr/bin/ld: app.o: в функции «_Dmain»: app.d:(.text._Dmain[_Dmain]+0xcb): undefined reference «_D4arsd3ttf7TtfFont6__ctorMFNcIAhZSQBhQBfQBe» /usr/bin/ld: app.d:(.text._Dmain[_Dmain]+0xfb): undefined reference «_D4arsd3ttf7TtfFont12renderStringMFIAaiJiJiZAh» /usr/bin/ld: app.d:(.text._Dmain[_Dmain]+0x297): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfiiiiZSQBqQBoQBl» /usr/bin/ld: app.d:(.text._Dmain[_Dmain]+0x2a2): undefined reference «_D4arsd5color5Color10alphaBlendMxFNaNbNiNeSQBpQBnQBkZQl» /usr/bin/ld: app.d:(.text._Dmain[_Dmain]+0x31a): undefined reference «_D4arsd3png8writePngFAyaCQx5color11MemoryImageZv» /usr/bin/ld: app.o: в функции «_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage»: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color1 MemoryImage]+0x1f): undefined reference «_D4arsd5image29guessImageFormatFromExtensionFAxaZEQBwQBu15ImageFileFormat» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11 emoryImage]+0x1d8): undefined reference «_D4arsd5image19loadImageFromMemoryFAxvZCQBm5color11MemoryImage» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11 emoryImage]+0x297): undefined reference «_D4arsd3png7readPngFAyaZCQx5color11MemoryImage» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11 emoryImage]+0x2a9): undefined reference «_D4arsd3bmp7readBmpFAyaZCQx5color11MemoryImage» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11 emoryImage]+0x2bb): undefined reference «_D4arsd4jpeg8readJpegFAxaZCQz5color11MemoryImage» /usr/bin/ld: app.d:(.text._D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11MemoryImage[_D4arsd5image__T17loadImageFromFileHTAyaZQzFQhZCQBu5color11 emoryImage]+0x341): undefined reference «_D4arsd5image7readSvgFAyaZCQz5color11MemoryImage» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11 emoryImage]+0x9ab): undefined reference «_D4arsd5color14TrueColorImage7__ClassZ» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11 emoryImage]+0x9c6): undefined reference «_D4arsd5color14TrueColorImage6__ctorMFNaNbNfiiZCQBuQBsQBp» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11 emoryImage]+0xa01): undefined reference «_D4arsd5color14TrueColorImage4Data6colorsMNgFNaNbNdNiNeZANgSQCgQCe5Color» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11 emoryImage]+0xc12): undefined reference «_D4arsd5color14TrueColorImage4Data6colorsMNgFNaNbNdNiNeZANgSQCgQCe5Color» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11 emoryImage]+0xd02): undefined reference «_D4arsd5color14TrueColorImage4Data6colorsMNgFNaNbNdNiNeZANgSQCgQCe5Color» /usr/bin/ld: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11MemoryImage[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZCQCf5color11 emoryImage]+0xd5e): undefined reference «_D4arsd5color14TrueColorImage4Data6colorsMNgFNaNbNdNiNeZANgSQCgQCe5Color» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi0ZQsMFMDFZhZSQDk5color5Color»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi0ZQsMFMDFZhZSQDk5color5Color[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi0ZQsMFMDFZhZSQDk color5Color]+0xab): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfiiiiZSQBqQBoQBl» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi0Vki3ZQyMFMDFZhZSQDq5color5Color»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi0Vki3ZQyMFMDFZhZSQDq5color5Color[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi0Vki3ZQyMFMDFZhZSQDq color5Color]+0x6f): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfiiiiZSQBqQBoQBl» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi0Vki4ZQyMFMDFZhZSQDq5color5Color»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi0Vki4ZQyMFMDFZhZSQDq5color5Color[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi0Vki4ZQyMFMDFZhZSQDq color5Color]+0x6f): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfiiiiZSQBqQBoQBl» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi1ZQsMFMDFZhZSQDk5color5Color»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi1ZQsMFMDFZhZSQDk5color5Color[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T11readColor16Vbi1ZQsMFMDFZhZSQDk color5Color]+0xab): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfiiiiZSQBqQBoQBl» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi1Vki3ZQyMFMDFZhZSQDq5color5Color»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi1Vki3ZQyMFMDFZhZSQDq5color5Color[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi1Vki3ZQyMFMDFZhZSQDq color5Color]+0x6f): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfiiiiZSQBqQBoQBl» /usr/bin/ld: app.o:app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi1Vki4ZQyMFMDFZhZSQDq5color5Color[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ__T13readColorTrueVbi1Vki4ZQyMFMDFZhZSQDq color5Color]+0x6f): далее есть ещё неопределённые ссылки на «_D4arsd5color5Color6__ctorMFNaNbNcNiNfiiiiZSQBqQBoQBl» /usr/bin/ld: app.o: в функции «_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ12loadColormapMFZv»: app.d:(.text._D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ12loadColormapMFZv[_D4arsd5targa__T11loadTgaImplTS3std5stdio4FileZQBfFKQwAxaZ12loadC lormapMFZv]+0x1d3): undefined reference «_D4arsd5color5Color5blackFNaNbNiNfZSQBiQBgQBd» /usr/bin/ld: app.o: в функции «_D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11MemoryImage»: app.d:(.text._D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11MemoryImage[_D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11 emoryImage]+0x62a): undefined reference «_D4arsd5color12IndexedImage7__ClassZ» /usr/bin/ld: app.d:(.text._D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11MemoryImage[_D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11 emoryImage]+0x643): undefined reference «_D4arsd5color12IndexedImage6__ctorMFNaNbNfiiZCQBsQBqQBn» /usr/bin/ld: app.d:(.text._D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11MemoryImage[_D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11 emoryImage]+0x653): undefined reference «_D4arsd5color14TrueColorImage7__ClassZ» /usr/bin/ld: app.d:(.text._D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11MemoryImage[_D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11 emoryImage]+0x66c): undefined reference «_D4arsd5color14TrueColorImage6__ctorMFNaNbNfiiZCQBuQBsQBp» /usr/bin/ld: app.d:(.text._D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11MemoryImage[_D4arsd3pcx__T11loadPcxImplTS3std5stdio4FileZQBfFKQwAxaZCQCd5color11 emoryImage]+0xa21): undefined reference «_D4arsd5color5Color6__ctorMFNaNbNcNiNfiiiiZSQBqQBoQBl» /usr/bin/ld: app.o:(.data._D27TypeInfo_S4arsd5color5Color6__initZ+0x48): undefined reference «_D4arsd5color5Color8toStringMxFNfZAya» /usr/bin/ld: app.o: в функции «_D4arsd3dds__T15ddsLoadFromFileZQsFS3std5stdio4FileZCQBz5color14TrueColorImage»: app.d:(.text._D4arsd3dds__T15ddsLoadFromFileZQsFS3std5stdio4FileZCQBz5color14TrueColorImage[_D4arsd3dds__T15ddsLoadFromFileZQsFS3std5stdio4FileZCQBz5color14Tru ColorImage]+0x213): undefined reference «_D4arsd3dds17ddsLoadFromMemoryFAxvZCQBi5color14TrueColorImage» collect2: error: ld execution ended with return code 1 Error: linker exited with status 1 ```
Apr 27 2022
next sibling parent Dennis <dkorpel gmail.com> writes:
On Wednesday, 27 April 2022 at 07:42:31 UTC, Alexander Zhirov 
wrote:
 ```d
 ~/programming/d/pic $ dmd app.d
 ```
Try passing the `-i` flag: `dmd -i app.d`. This way, imported modules are actually compiled and linked too. Currently it looks like you import arsd, but then don't link the library, so it complains about undefined references to functions in arsd.
Apr 27 2022
prev sibling parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Wednesday, 27 April 2022 at 07:42:31 UTC, Alexander Zhirov 
wrote:
 On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote:
 Sample code would be:
My inattention, it was necessary to write like this: ```sh dmd app.d -i arsd/image.d ``` Now everything is compiled and really the way I need it! Thank you very much! There are two more questions left: 1) How to write to jpeg correctly? 2) How can I reduce the size of the executable file? And then 3 megabytes is too much for such a utility.
Apr 27 2022
parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Wednesday, 27 April 2022 at 08:29:27 UTC, Alexander Zhirov 
wrote:
 On Wednesday, 27 April 2022 at 07:42:31 UTC, Alexander Zhirov 
 wrote:
 On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote:
 Sample code would be:
1) How to write to jpeg correctly?
That's how I managed to write to jpeg: ```d writeJpeg("dst.jpg", tci); ``` Now I would like to reduce the size of the executable file and it would be great at all!
Apr 27 2022
parent reply Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Wednesday, 27 April 2022 at 09:27:24 UTC, Alexander Zhirov 
wrote:
 Now I would like to reduce the size of the executable file and 
 it would be great at all!
Try the `-release` option to `dmd`. Or use LDC. -- Bastiaan.
Apr 27 2022
parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Wednesday, 27 April 2022 at 11:59:20 UTC, Bastiaan Veelo wrote:

 Or use LDC.
Gorgeous! LDC has compressed my code at times! Thanks again to everyone for help! Special thanks to **Adam Ruppe**
Apr 27 2022
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Wednesday, 27 April 2022 at 14:40:59 UTC, Alexander Zhirov 
wrote:
 Gorgeous! LDC has compressed my code at times!
How small did it get? And with my libs if you import the other ones like `arsd.png` or `arsd.jpeg` directly instead of `arsd.image` that MIGHT help trim it down by removing support for other formats. I'm not sure though, none of them are especially big but it might add up.
Apr 27 2022
parent reply Alexander Zhirov <azhirov1991 gmail.com> writes:
On Wednesday, 27 April 2022 at 16:07:53 UTC, Adam D Ruppe wrote:

 How small did it get?
```sh dmd: 3136896 byte ldc: 223952 byte ```
 And with my libs if you import the other ones like `arsd.png` 
 or `arsd.jpeg` directly instead of `arsd.image` that MIGHT help 
 trim it down by removing support for other formats.  I'm not 
 sure though, none of them are especially big but it might add 
 up.
Yes, just now, on your advice, I did so. The size has become a little smaller! 😌
Apr 27 2022
parent Alexander Zhirov <azhirov1991 gmail.com> writes:
On Wednesday, 27 April 2022 at 16:37:21 UTC, Alexander Zhirov 
wrote:
 On Wednesday, 27 April 2022 at 16:07:53 UTC, Adam D Ruppe wrote:

 How small did it get?
```sh dmd: 3136896 byte ldc: 223952 byte ```
but uses libraries ldc-shared.so ```sh linux-vdso.so.1 (0x00007ffef5d2d000) libphobos2-ldc-shared.so.99 => /usr/lib64/libphobos2-ldc-shared.so.99 (0x00007f667e9ee000) libdruntime-ldc-shared.so.99 => /usr/lib64/libdruntime-ldc-shared.so.99 (0x00007f667e8ac000) libm.so.6 => /usr/lib64/libm.so.6 (0x00007f667e7c5000) libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x00007f667e7a9000) libc.so.6 => /usr/lib64/libc.so.6 (0x00007f667e589000) /usr/lib64/ld-linux-x86-64.so.2 (0x00007f667eebe000) ``` And if without using dynamic libraries, it weighs `1219776` bytes ```sh linux-vdso.so.1 (0x00007ffca9ad0000) librt.so.1 => /lib/librt.so.1 (0x00007f6240fc4000) libdl.so.2 => /lib/libdl.so.2 (0x00007f6240fbe000) libpthread.so.0 => /lib/libpthread.so.0 (0x00007f6240f9d000) libm.so.6 => /lib/libm.so.6 (0x00007f6240e58000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f6240e3e000) libc.so.6 => /lib/libc.so.6 (0x00007f6240c74000) /lib64/ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 (0x00007f6240ff7000) ```
Apr 27 2022
prev sibling parent reply matheus <matheus gmail.com> writes:
On Wednesday, 27 April 2022 at 00:03:25 UTC, Adam Ruppe wrote:
 ...
I know about Adam Ruppe's work, I already used his terminal.d, but I think that unfortunately most people don't and I think it should be announced more in these parts. For me arsd is for D what stb is for C. I think in the first time running any D compiler, it should blink in the terminal in Yellow/Pink or whatever color you like, and show some info like: Are you starting a new project any need some libs? Do you know about arsd? If not then go to: https://github.com/adamdruppe/arsd. :) matheus.
Apr 27 2022
next sibling parent Alexander Zhirov <azhirov1991 gmail.com> writes:
On Wednesday, 27 April 2022 at 17:07:54 UTC, matheus wrote:

 I think in the first time running any D compiler, it should 
 blink in the terminal in Yellow/Pink or whatever color you 
 like, and show some info like: Are you starting a new project 
 any need some libs? Do you know about arsd? If not then go to: 
 https://github.com/adamdruppe/arsd. :)
Hahaha 😄 This is the truth! I totally agree!
Apr 27 2022
prev sibling parent Adam D Ruppe <destructionator gmail.com> writes:
On Wednesday, 27 April 2022 at 17:07:54 UTC, matheus wrote:
 I know about Adam Ruppe's work, I already used his terminal.d, 
 but I think that unfortunately most people don't and I think it 
 should be announced more in these parts.
tbh sometimes i just don't feel like answering messages. even this one, i was like "i can do that easily, but do i want to support another user?" but meh i had a few mins to kill anyway
 For me arsd is for D what stb is for C.
Note that a few of those modules are stb ports over to D. I wrote the png and bmp modules myself, for example, but the jpeg is a port from C (that port done by ketmar on irc) and the ttf one is stb_ttf ported to D then with a little wrapper struct pasted on top. One thing I'm kinda proud of though is my OperatingSystemFont class in simpledisplay which can load a font and then pass it into the ttf thing and/or the nanovega module for all kinds of custom effects. You don't necessarily have to package your own ttf files!
Apr 27 2022