How to resize an image ? 🤔

vnr cfcr at gmail.com
Fri Dec 25 22:59:55 UTC 2020


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?


More information about the Digitalmars-d-learn mailing list