Re: How to resize an image ? 樂
On Friday, 25 December 2020 at 20:59:03 UTC, vnr wrote: Hello For a small "script" that generates printable files, I would need to change the size of an image (which is loaded into memory as an array of bytes) to shrink it to scale if it exceeds the A4 page size. To load the images into memory and generate a PDF, I use the "printed" package. It is not very provided but is sufficient for my use, I just need the resize option... Is there a relatively simple way to do this? Thank you. printed use the DPI information in your image to set the target size. You do not necessarily need to change the pixels. Save your PNG / JPEG with proper DPI information.
Re: How to resize an image ? 樂
On 12/25/20 12:59 PM, vnr wrote: > Is there a relatively simple way to do this? I have a minimalist photo album program that resizes images with the help of the magickwand library: https://github.com/acehreli/alibum It has only the magickwand bindings that I needed. Ali P.S. The program takes a directory of pictures and creates static html pages as an album, which includes thumbnails.
Re: How to resize an image ? 樂
On Friday, 25 December 2020 at 22:59:55 UTC, vnr wrote: tmp.data = cast(ubyte[]) myImageData; You set bytes here but an IndexedImage also needs a palette which you didn't set up. What format is your myImageData in? It might be more appropriate to set it to a TrueColorImage. IndexedImage: each pixel is one byte and it refers to a Color[] palette. TrueColorImage: each pixel is 4 bytes, red, green, blue, and alpha inline. If your image data isn't already read, you might load it as a different thing instead with loadImageFromMemory. It all depends what format you are starting with. writeln(guessImageFormatFromMemory(tci.imageData.bytes)); // "Unknown" That function is also for reading files, not raw bytes like inside the classes. The classes are supposed to already be in a specific layout.
Re: Get the code of any D-entity as string?
On 12/25/20 1:25 PM, sighoya wrote: > Is generally possible to get the declaration of a type/module/value as > string in traits? I am probably misunderstanding it but there is the .stringof property for all types: T.stringof. > I want also to read > declarations from types outside my source folders, e.g. from those > located in dyn libs. I am probably stating the obvious but you normally import the interesting modules of that library anyway and the type information is available that way. Ali
Re: How to resize an image ? 樂
On Friday, 25 December 2020 at 21:05:19 UTC, Ferhat Kurtulmuş wrote: On Friday, 25 December 2020 at 20:59:03 UTC, vnr wrote: Hello For a small "script" that generates printable files, I would need to change the size of an image (which is loaded into memory as an array of bytes) to shrink it to scale if it exceeds the A4 page size. To load the images into memory and generate a PDF, I use the "printed" package. It is not very provided but is sufficient for my use, I just need the resize option... Is there a relatively simple way to do this? Thank you. Check this out: https://github.com/adamdruppe/arsd/blob/master/image.d#L434 Thank you very much, this solution seems to be really suitable. Nevertheless, when I try to use the given function, the value it returns seems to be null. Here is my code: // Define an image usable by arsd.image auto tmp = new IndexedImage(myWidth, myHeight); tmp.data = cast(ubyte[]) myImageData; // Setting the new image from the 'tmp' resized auto newImg = imageResize(tmp, 500, 500); // Testing writeln(test.imageData.bytes[0 .. 50]); // [0, 0, 0, 0, ..., 0] writeln(guessImageFormatFromMemory(tci.imageData.bytes)); // "Unknown" This code seems relatively logical to me, but it doesn't work, as we can see, the resulting array of bytes is filled with 0, as if the resizeImage function had had no effect. Do you know where the error is?
Re: Get the code of any D-entity as string?
On Friday, 25 December 2020 at 21:25:40 UTC, sighoya wrote: Is generally possible to get the declaration of a type/module/value as string in traits? No.
Get the code of any D-entity as string?
I've read a bit in Dlang traits. It now has the ability to retrieve all method signatures of an overload set. Big plus from me. Is generally possible to get the declaration of a type/module/value as string in traits? I didn't have any concrete use case for it, but it would essentially allow us to reflect over any code (we may have to respect privacy, of course). On top of that, people could write their own token or ast frameworks as library solutions. Further, most of the trait functionality given in the trait library could be simply implemented as a library solution. I don't know D enough to be sure it isn't yet possible. Theoretically, we could read all files in a source folder, but I want also to read declarations from types outside my source folders, e.g. from those located in dyn libs.
Re: C++ or D?
On Thursday, 24 December 2020 at 08:36:54 UTC, RSY wrote: You can use GC, you can disable it, you can use malloc, it suits all your need! Not to forget the availability of refcounted (shared) and unique ptr too in D.
Re: How to resize an image ? 樂
On Friday, 25 December 2020 at 20:59:03 UTC, vnr wrote: Hello For a small "script" that generates printable files, I would need to change the size of an image (which is loaded into memory as an array of bytes) to shrink it to scale if it exceeds the A4 page size. To load the images into memory and generate a PDF, I use the "printed" package. It is not very provided but is sufficient for my use, I just need the resize option... Is there a relatively simple way to do this? Thank you. Check this out: https://github.com/adamdruppe/arsd/blob/master/image.d#L434
How to resize an image ? 樂
Hello For a small "script" that generates printable files, I would need to change the size of an image (which is loaded into memory as an array of bytes) to shrink it to scale if it exceeds the A4 page size. To load the images into memory and generate a PDF, I use the "printed" package. It is not very provided but is sufficient for my use, I just need the resize option... Is there a relatively simple way to do this? Thank you.
Re: How to store a pointer to class contructor
On Thursday, 24 December 2020 at 10:23:09 UTC, Dmitriy Asondo wrote: I expect code like this: -- class OloloService {} class BlablaService {} auto servicesList = [OloloService, BlablaService]; auto serviceInstance = new servicesList[1](args); -- Here's a slightly different version that I think is closer to your original example: import std; interface Service {} mixin template Constructor() { this(int a) { } } class OloloService : Service { mixin Constructor; } class BlablaService : Service { mixin Constructor; } Service function(int) create(T)() { return a => new T(a); } void main() { auto servicesList = [create!OloloService, create!BlablaService]; auto serviceInstance = servicesList[1](3); writeln(serviceInstance); } Since D is a statically typed language you need a form of base type if you want to store a list of values of different types. In this case, the base type is `Service`. If you want to have a constructor, as you do in your original example, the constructor needs to have the same signature for all types, the mixin template helps with that. You can use a tuple as well to store different values of different types. But then everything need to be known at compile time. That is, the index, in your case. -- /Jacob Carlborg