Please let me know if there is a way to automatically compress the uploaded photo.

Asked 2 years ago, Updated 2 years ago, 34 views

To everyone with knowledge

I posted it yesterday, but I thought it might be a misleading question, so I will post it again.

We are currently receiving a request and consultation from a certain customer for a proposal for an application reception system.
(Our company has the business know-how, and this is a request for a proposal based on the evaluation.)


from the customer ·You will need a certificate of identification (license, my card, etc.) to apply for the service.
 Therefore, please send an image file of the identification certificate from the application reception site
 I want to upload it.
·In many cases, the identification form is supposed to be taken with a smartphone, but
 Recently, the camera function of the smartphone has improved, and the capacity of the image file is large
 There is a tendency to
 On the other hand, enable the capacity of the hard drive on the server running the system
 I want to use it.
 Therefore, I want to compress the uploaded image file and save the HDD.
 (Using a compression tool to manually compress the application for the previous day seems to be unpleasant.)

The above request has been made.
   *Personally, even if I compress the image file, the file capacity will not be dramatically reduced.
    I think...

To meet your needs,
1. Automatic compression server side transmission when uploading files on the application web screen.
  (Development of application web screen using HTML+Javascript Or HTML+PHP?)

2. Compress the sent image file on the server side
  (Create PG to compress image files using Java.
   Register the PG you created in a time schedule and run it automatically)

I can think of the above two things.

I'm guessing that 1 will be difficult to realize.
As for 2, I found the following example for reference using ImageIO as a compressed PG online.

public static byte[]resize (final byte[]) src, final double scale)throws IOException
{
    try(ByteArrayInputStream is=newByteArrayInputStream(src);
        ByteArrayOutputStreamos = new ByteArrayOutputStream()) {
            BufferedImage srcImage=ImageIO.read(is);
            BufferedImage destImage=resizeImage(srcImage, scale);

            // Storage quality will be "75"
            ImageIO.write(destImage, "jpeg", os);
            returnos.toByteArray();
        }
}

I understand that you cannot specify the preservation quality, but it is for identification, so
I don't think it will be a problem.

[Question]
The preface is longer, but
·Please let me know if there is a good way about 1.
·Please let me know if there is a good PG for 2.
·Please let me know if there are any other methods besides 1 and 2.

Thank you for your cooperation.

javascript php java

2022-09-29 22:03

1 Answers

Front side image processing
I think the big trend is to write Javascript in Canvas, process the size, then write it in base64 and post it as blob.

Resize and upload local images in your browser https://qiita.com/komakomako/items/8efd4184f6d7cf1363f2
Learn more about the program here.

However, please check Canvas as it has browser limitations.
https://developer.mozilla.org/ja/docs/Web/HTML/Canvas

Server-side processing using Java
I don't understand this.

Other than that,
If you want to run it on the server side, you can do it by using imagemagic.
http://imagemagick.rulez.jp/
You will install imagemagic on the server and run it on the command line.
I think it can be installed and used on most servers.

PHP is a server-side language, not a front-side language.
PHP has an extended library, so
http://php.net/manual/ja/book.imagick.php
I think you can use this one.


2022-09-29 22:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.