Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QImage setText and remove it
Qt 6.12 LTS is out! See what's new in the release blog

QImage setText and remove it

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samdol
    wrote on last edited by
    #1

    Hi,

    We can create an image file with text by

      QImage image("source.jpeg");
      QImageWriter writer("target.jpeg");
      writer.setText("Author", "John Smith");
      writer.write(image);
    

    After creating target.jpeg with the text, how can I remove the text from
    target.jpeg? I did writer.setText("", ""); but it did not make any change.

    This process, file -> QImage -> file, resamples image so the size of file
    changes (for example, source.jpge(200 Kb) -> target.jpeg(140 Kb)). Is there
    any way I can just edit text of source.jpeg without resampling, so the size
    of source.jpeg effectively remains the same?

    joeQJ 1 Reply Last reply
    0
    • S samdol

      Hi,

      We can create an image file with text by

        QImage image("source.jpeg");
        QImageWriter writer("target.jpeg");
        writer.setText("Author", "John Smith");
        writer.write(image);
      

      After creating target.jpeg with the text, how can I remove the text from
      target.jpeg? I did writer.setText("", ""); but it did not make any change.

      This process, file -> QImage -> file, resamples image so the size of file
      changes (for example, source.jpge(200 Kb) -> target.jpeg(140 Kb)). Is there
      any way I can just edit text of source.jpeg without resampling, so the size
      of source.jpeg effectively remains the same?

      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by joeQ
      #2

      @samdol hi,friend,welcome.

      It is Ok in my OS.

      X:MacOS X$ file source.jpeg 
      source.jpeg: JPEG image data, JFIF standard 1.01
      

      writer.setText("Author", "John Smith");

      X:MacOS X$ file target.jpeg 
      target.jpeg: JPEG image data, JFIF standard 1.01, comment: "Author: John Smith??"
      

      writer.setText("Author", "");

      X:MacOS X$ file target_1.jpeg 
      target_1.jpeg: JPEG image data, JFIF standard 1.01, comment: "Author: ??"
      

      writer.setText("", "");

      X:MacOS X$ file target_2.jpeg 
      target_2.jpeg: JPEG image data, JFIF standard 1.01
      
      X:MacOS X$ ll
      total 120
      -rw-r--r--@ 1 X  staff   3787 10 16 11:24 source.jpeg
      -rw-r--r--  1 X  staff   3683 10 16 11:27 target.jpeg
      -rw-r--r--  1 X  staff   3673 10 16 11:54 target_1.jpeg
      -rw-r--r--  1 X  staff   3661 10 16 11:56 target_2.jpeg
      
      

      But, why the target_2 image size is smaller than source image.

      Just do it!

      jsulmJ S 2 Replies Last reply
      1
      • joeQJ joeQ

        @samdol hi,friend,welcome.

        It is Ok in my OS.

        X:MacOS X$ file source.jpeg 
        source.jpeg: JPEG image data, JFIF standard 1.01
        

        writer.setText("Author", "John Smith");

        X:MacOS X$ file target.jpeg 
        target.jpeg: JPEG image data, JFIF standard 1.01, comment: "Author: John Smith??"
        

        writer.setText("Author", "");

        X:MacOS X$ file target_1.jpeg 
        target_1.jpeg: JPEG image data, JFIF standard 1.01, comment: "Author: ??"
        

        writer.setText("", "");

        X:MacOS X$ file target_2.jpeg 
        target_2.jpeg: JPEG image data, JFIF standard 1.01
        
        X:MacOS X$ ll
        total 120
        -rw-r--r--@ 1 X  staff   3787 10 16 11:24 source.jpeg
        -rw-r--r--  1 X  staff   3683 10 16 11:27 target.jpeg
        -rw-r--r--  1 X  staff   3673 10 16 11:54 target_1.jpeg
        -rw-r--r--  1 X  staff   3661 10 16 11:56 target_2.jpeg
        
        

        But, why the target_2 image size is smaller than source image.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @joeQ said in QImage setText and remove it:

        But, why the target_2 image size is smaller than source image.

        Because it contains less information I guess (no Author at all).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • joeQJ joeQ

          @samdol hi,friend,welcome.

          It is Ok in my OS.

          X:MacOS X$ file source.jpeg 
          source.jpeg: JPEG image data, JFIF standard 1.01
          

          writer.setText("Author", "John Smith");

          X:MacOS X$ file target.jpeg 
          target.jpeg: JPEG image data, JFIF standard 1.01, comment: "Author: John Smith??"
          

          writer.setText("Author", "");

          X:MacOS X$ file target_1.jpeg 
          target_1.jpeg: JPEG image data, JFIF standard 1.01, comment: "Author: ??"
          

          writer.setText("", "");

          X:MacOS X$ file target_2.jpeg 
          target_2.jpeg: JPEG image data, JFIF standard 1.01
          
          X:MacOS X$ ll
          total 120
          -rw-r--r--@ 1 X  staff   3787 10 16 11:24 source.jpeg
          -rw-r--r--  1 X  staff   3683 10 16 11:27 target.jpeg
          -rw-r--r--  1 X  staff   3673 10 16 11:54 target_1.jpeg
          -rw-r--r--  1 X  staff   3661 10 16 11:56 target_2.jpeg
          
          

          But, why the target_2 image size is smaller than source image.

          S Offline
          S Offline
          samdol
          wrote on last edited by
          #4

          @joeQ
          Thank you for testing on Mac OS. I don't know why, but I could not remove it on Windows. It is interesting you get the target file size which is about the same as source file size. Could you get the similar file size when you try jpg file of size ~ 10MByte?

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt
          • Unsolved