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

  • SEARCH
  • Home
  • 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 8316865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:27:16+00:00 2026-06-08T21:27:16+00:00

In the following code, that stores a jpg in db, I need to know

  • 0

In the following code, that stores a jpg in db, I need to know how to first change the jpg to 40% quality and then save? i tried with imagejpg, but it saves null-files:

function exportGraphics($table_name)
{
    $odbc_query = "SELECT * FROM " . $table_name;
    mkdir("TI/" . $table_name);

    $data = odbc_exec($this->odbc_id, $odbc_query);
    odbc_longreadlen($data, 10485760); // 10MB = 10485760
    while (odbc_fetch_row($data)) {
        $row = odbc_fetch_array($data);
        if ($row['GRD_ID'] != "") {
            $file_name_jpg = "TI/" . $table_name . "/" . $row['GRD_ID'] . ".jpg";
            $file = fopen($file_name_jpg, "w");
            fputs($file, $row['GRD_GRAPHIC']);
            fclose($file);
            set_time_limit(3600);
            unset($row);
        }
    }
    print "Ýêñïîðò êàðòèíîê èç òàáëèöû " . $table_name . " çàâåðøåí!";
}

Warning: imagecreatefromstring() [function.imagecreatefromstring]: gd
warning: one parameter to a memory allocation multiplication is
negative or zero, failing operation gracefully in
X:\denwer\www\denwer\tecdoc3.php on line 103

Warning: imagecreatefromstring() [function.imagecreatefromstring]:
Passed data is not in ‘WBMP’ format in
X:\denwer\www\denwer\tecdoc3.php on line 103

Warning: imagecreatefromstring() [function.imagecreatefromstring]:
Couldn’t create GD Image Stream out of Data in
X:\denwer\www\denwer\tecdoc3.php on line 103

Warning: imagecreatefromstring() [function.imagecreatefromstring]: gd
warning: one parameter to a memory allocation multiplication is
negative or zero, failing operation gracefully in
X:\denwer\www\denwer\tecdoc3.php on line 103

original code:

 function exportGraphics($table_name) {
 $odbc_query = "SELECT * FROM " . $table_name;
 mkdir("TI/" . $table_name);

 $data = odbc_exec($this->odbc_id, $odbc_query);
 odbc_longreadlen($data, 10485760); //10MB = 10485760
 while(odbc_fetch_row($data)) 
 { 
 $row = odbc_fetch_array($data);
 if($row['GRD_ID'] != "") {
 $file_name_jp2 = "TI/" . $table_name . "/" . $row['GRD_ID'] . ".jp2";
 $file = fopen ($file_name_jp2, "w");
 fputs($file, $row['GRD_GRAPHIC']);
 fclose($file);
 set_time_limit(0);
 unset($row);
 }
 }
 print "Ýêñïîðò êàðòèíîê èç òàáëèöû " . $table_name . " çàâåðøåí!";
 }
  • 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-08T21:27:18+00:00Added an answer on June 8, 2026 at 9:27 pm

    Try this:

    function exportGraphics($table_name) {
        $odbc_query = "SELECT * FROM " . $table_name;
        mkdir("TI/" . $table_name);
    
        $data = odbc_exec($this->odbc_id, $odbc_query);
        odbc_longreadlen($data, 10485760); //10MB = 10485760
        while(odbc_fetch_row($data))
        {
            $row = odbc_fetch_array($data);
            if($row['GRD_ID'] != "") {
                $file_name_jpg = "TI/" . $table_name . "/" . $row['GRD_ID'] . ".jpg";
    
                // create GD graphic from string, call imagejpeg to save new image
                $im = imagecreatefromstring($row['GRD_GRAPHIC']);
                imagejpeg($im, $file_name_jpg, 40);
    
                set_time_limit(3600);
                unset($row);
            }
        }
        print "Ýêñïîðò êàðòèíîê èç òàáëèöû " . $table_name . " çàâåðøåí!";
    }
    

    Or is that exactly what you tried?

    If for some reason that doesn’t work, you can try:

    $im = imagecreatefromstring($row['GRD_GRAPHIC']);
    ob_start();
    imagejpeg($im, null, 40);
    $imgData = ob_get_contents();
    ob_end_clean();
    
    $file = fopen ($file_name_jpg, "w+b");
    fputs($file, $imgData);
    fclose($file);
    

    EDIT: The reason GD isn’t working is because it doesn’t support JPEG-2000 file format

    Possible solution: Install imagemagick on the server and try code like this:

    $file_name_jpg = "TI/" . $table_name . "/" . $row['GRD_ID'] . ".jp2";
    $file_out_jpg  = str_replace('.jp2', '.jpg', $file_name_jpg);
    
    file_put_contents($file_name_jpg, $row['GRD_GRAPHIC']);
    
    // execute imagemagick convert to change to jpeg with quality 40
    exec("/usr/bin/convert $file_name_jpg -quality 40 -format jpg $file_out_jpg");
    unlink($file_name_jpg); // get rid of temp jp2 file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code that takes in some words, stores them
I have the following code that has @item.ID from razor: <a href=# id=deleteitem(@item.ID)>Delete</a> When
I have the following code that gets the MAC address of an interface: static
I have the following code that opens a new popup window while disabling the
I have the following code that fails when i run it. my .h file:
I have the following code that returns a .CSV file when a link is
In the following code that skips comments, what's meaning of BEGIN(INITIAL) ? %x C_COMMENT
I have the following code that works fine up to the last line in
I have the following code that simply moves my image across the screen: /*
I have the following code that sets a background if user has uploaded to

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.