Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:14:57+00:00 2026-06-13T11:14:57+00:00

I am using this code to convert a Bitmap to Base64 : ByteArrayOutputStream baos

  • 0

I am using this code to convert a Bitmap to Base64:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, **quality**, baos);
byte[] b = baos.toByteArray();
base64code = Base64.encodeToString(b, Base64.DEFAULT);

and receiving it at the server side, this way:

$strImage = preg_replace('!\s*!', '', trim($this->input->post('image')));
        $thefile = base64_decode($strImage);
        $img = imagecreatefromstring($thefile);
        //header('Content-Type: image/jpeg');
        header('Content-Type: bitmap; charset=utf-8');
        imagesavealpha($img, true);
        imagejpeg($img,'./images/temp/testing.jpg',100);
        imagedestroy($img);

Problem:

The actual image size which i am picking from the device gallery to send to the server is 344 kb When i set the quality = 0 and show a spinner dialog util the base64 string is being sent to the server it takes 5 secs to send, and the image received at the server side is 344 Kb but if i am setting quality = 100 it takes 60-70 secs to send, and the image i receive at the server side is 1.7 Mb

Question:

why am i getting the actual size when using quality = 0 and nearly 5 times bigger image when quality = 100

Note:

When i am setting the quality = 100 and change

imagejpeg($img,'./images/temp/testing.jpg',100);

to

imagejpeg($img,'./images/temp/testing.jpg',10);

it takes 60-70 secs to send but the image received on the server side is too small 67 Kb

Thank You

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:14:58+00:00Added an answer on June 13, 2026 at 11:14 am

    I would think that @EJTH is correct in that 0 might mean to not re-compress the image at all. Any other value (1-100) is probably first converting your image to a bitmap (which would be very large) then compressing to the target quality jpeg. This re-compression takes processing time to complete so you see 60-70 secs for values other than 0.

    I’ve not used the Bitmap#compress method before though, so the above is speculation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code to attempt to convert a float to an int, then
I am using this code for on android just trying to convert string to
I'm using this code to convert a jpg image into a png 8. The
Part 1) I have a bitmap/jpeg image. I need to convert this image into
I'm using this code to capture the screen: public Bitmap CaptureWindow(IntPtr handle) { //
I'm using this well known sample code from Apple to convert camera buffer still
Using this code, i am able to send a notification to my own device.
Using this code to zip a folder and it works perfect on small files
Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:
Using This code: I am tring to fill the page with the data and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.