I want to create an image file by specifying the capacity.

Asked 2 years ago, Updated 2 years ago, 55 views

I am using macOS Catalina (10.15.7).

In order to check if a form with a capacity limit (file size limit) for image uploads has been properly validated when the capacity exceeds that limit, I think we may prepare a test image file.
For example, if 10MB is the upper limit, prepare a 10MB image.

I thought I could use the dd command to create test data with the file size specified, so I created a file with only the extension jpg by referring to the following article.
https://qiita.com/toshihirock/items/6cb99a85d86f524bc153
There was an error on the server side if the image corruption check or MIME type check was caught, so I thought it would be possible to resize the actual image to the specified capacity.

I used the library jpegoptim to refer to the article around here. https://sato-labo.mydns.jp/2017/02/jpegoptim/
-S500 and other options did not produce the desired file size, such as shaking up or shaking down.

If anyone knows how to create an image file with a specified capacity, could you tell me?(Is there such a way?)

macos image

2022-09-30 14:34

1 Answers

After the jpeg file smaller than the appropriate purpose, put a fraction of the trash made of dd
Why don't you fill it up?

Many libraries that determine MIME only look at headers.
When decoding and displaying jpeg, the commonly used libjpeg is jpeg
Simply ignore the trash behind the file and decode it successfully with just a warning.

It looks like this when you write with one liner.Just 30,000 bytes of nice.jpg,
After the smaller test.jpg, we attach the zero-filled data together.

$size_tobe=30000;frac=$(expr${size_tobe}-$(stat--printf="%s" test.jpg)); ddif=/dev/zero of=frac.datbs=1 count=$frac;cat test.jpg frac.dat>nice.jpg


2022-09-30 14:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.