Ticket #2094 (new enhancement)

Opened 1 year ago

Last modified 4 months ago

[with patch, needs more work] Add jpeg support to gd

Reported by: boothby Assigned to: was
Priority: major Milestone: sage-3.4
Component: graphics Keywords: editor_craigcitro
Cc:

Description

jpeg is a common format that most people keep their pictures in -- let's support it!

Attachments

deps.patch (1.2 kB) - added by boothby on 02/07/2008 05:35:53 PM.
install.patch (258 bytes) - added by boothby on 02/07/2008 05:36:16 PM.

Change History

02/07/2008 05:22:49 PM changed by boothby

02/07/2008 05:35:53 PM changed by boothby

  • attachment deps.patch added.

02/07/2008 05:36:16 PM changed by boothby

  • attachment install.patch added.

02/07/2008 05:38:31 PM changed by boothby

  • summary changed from Add jpeg support to gd to [with patch] Add jpeg support to gd.

Works on intel 64 / ubuntu -- needs testing on amd64, mac osx, 386, etc.

02/08/2008 02:27:01 PM changed by mabshoff

  • milestone set to sage-2.10.2.

03/11/2008 10:15:41 PM changed by rlm

  • milestone changed from sage-2.11 to sage-2.10.4.

04/06/2008 12:53:51 PM changed by boothby

  • summary changed from [with patch] Add jpeg support to gd to [with patch, needs review] Add jpeg support to gd.

04/27/2008 04:52:41 PM changed by mhampton

I'm confused on how to test this - can you provide an example of using jpeg?

I think I have everything installed/patched OK, I'm just not sure how to use it. I tried hacking the plot save command, but ran into trouble with matplotlib since it doesn't have good jpeg support.

06/15/2008 02:36:48 PM changed by craigcitro

  • keywords set to editor_craigcitro.

06/16/2008 01:55:58 PM changed by boothby

use the following to test:

import gd, os, cStringIO, urllib2


def simple():
    im = gd.image((200, 200))

    white = im.colorAllocate((255, 255, 255))
    black = im.colorAllocate((0, 0, 0))
    red = im.colorAllocate((255, 0, 0))
    blue = im.colorAllocate((0, 0, 255))

    im.colorTransparent(white)
    im.interlace(1)

    im.rectangle((0,0),(199,199),black)
    im.arc((100,100),(195,175),0,360,blue)
    im.fill((100,100),red)

    f=open("xx.png","w")
    im.writePng(f)
    f.close()

    f=open("xx.jpg", "w")
    im.writeJpeg(f,100)
    f.close()

    f=cStringIO.StringIO()
    im.writePng(f)
    print "PNG size:", len(f.getvalue())
    f.close()
    
    f = urllib2.urlopen("http://www.gnu.org/graphics/gnu-head-sm.jpg")
    im = gd.image(f, "jpg")
    f.close()
    im.writePng("xy.png")
    print "GNU Image Size:", im.size()

simple()

06/16/2008 02:42:26 PM changed by boothby

Instructions for reviewer(s):

The deps/install patches are diffed against files in the Sage distribution which are not (for better or worse) under revision control. To test, please install the spkgs in the order (jpeg, gd, gdmodule). Then, run the sample code above.

06/16/2008 02:47:03 PM changed by mhampton

I get the following error (the spkgs seem to have installed without errors):

Traceback (most recent call last):

File "/Volumes/D/sage-3.0.2/local/lib/python2.5/site-packages/gd.py", line 10, in <module>

import _gd

ImportError?: dlopen(/Volumes/D/sage-3.0.2/local/lib/python2.5/site-packages/_gd.so, 2): Symbol not found: _jpeg_std_error

Referenced from: /Volumes/D/sage-3.0.2/local/lib//libgd.2.dylib Expected in: flat namespace

06/16/2008 11:38:08 PM changed by boothby

06/19/2008 12:33:14 PM changed by craigcitro

  • summary changed from [with patch, needs review] Add jpeg support to gd to [with patch, with negative review] Add jpeg support to gd.

Tom agrees that this patch needs work to function on a Mac. He'll get to it soon-ish.

06/19/2008 09:20:00 PM changed by craigcitro

Notice that these are (basically) the same errors we're seeing on #3324.

08/30/2008 11:49:57 AM changed by mabshoff

This is a framework vs. sane library issue - I will likely have a workaround for this in the not too distant future.

Cheers,

Michael

09/20/2008 03:27:31 PM changed by mabshoff

  • summary changed from [with patch, with negative review] Add jpeg support to gd to [with patch, needs review] Add jpeg support to gd.

Since we now do no longer build anything against the Apple IOKit Framework this spkg should be re-reviewed.

Cheers,

Michael

09/20/2008 07:57:54 PM changed by mhampton

  • summary changed from [with patch, needs review] Add jpeg support to gd to [with patch, needs more work] Add jpeg support to gd.

I am now having problems different from before. The jpeg spkg seems to install OK, and when installing the gd spkg I get the following encouraging message from the configuring:

** Configuration summary for gd 2.0.33:

   Support for PNG library:          yes
   Support for JPEG library:         yes
   Support for Freetype 2.x library: yes
   Support for Fontconfig library:   no
   Support for Xpm library:          no
   Support for pthreads:             yes

...but then the build fails, and there is a message:

*** Warning: linker path does not have real file for library -ljpeg.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libjpeg and none of the candidates passed a file format test
*** using a file magic. Last file checked: /Volumes/D/sage-3.1.2/local/lib//libjpeg.a
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.

...which occurs before the actual error:

/usr/libexec/gcc/i686-apple-darwin8/4.0.1/ld: Undefined symbols:
_gdImageCreateFromJpeg
_gdImageJpeg
collect2: ld returned 1 exit status
make[2]: *** [annotate] Error 1
make[2]: Leaving directory `/Volumes/D/sage-3.1.2/spkg/build/gd-2.0.33.p7/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/Volumes/D/sage-3.1.2/spkg/build/gd-2.0.33.p7/src'
make: *** [all] Error 2
Error building gd.

It would be very nice to have this stuff working; being able to quickly import images as matrices is something matlab and mathematica users take for granted. Unfortunately I don't think I have the skills needed to fix this.

09/20/2008 08:17:28 PM changed by mhampton

One more note: since gd has evolved to 2.0.35, I tried installing that and it seemed to work but the suggested test still crashed with

sage: import gd, os, cStringIO, urllib2
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)

/Volumes/D/sage-3.1.2/<ipython console> in <module>()

/Volumes/D/sage-3.1.2/local/lib/python2.5/site-packages/gd.py in <module>()
      8 library."""
      9 
---> 10 import _gd
     11 from _gd import *
     12 del image

ImportError: dlopen(/Volumes/D/sage-3.1.2/local/lib/python2.5/site-packages/_gd.so, 2): Symbol not found: _gdImageCreateFromJpeg
  Referenced from: /Volumes/D/sage-3.1.2/local/lib/python2.5/site-packages/_gd.so
  Expected in: dynamic lookup

although I might have messed up in manually installing gd-2.0.35.

09/20/2008 10:20:16 PM changed by mabshoff

I can fix this on OSX. Give me a little while. Besides adding the jpeg.spkg this also needs matching fixes to the gd.spkg

Cheers,

Michael

(follow-up: ↓ 20 ) 09/22/2008 09:54:12 AM changed by mhampton

OK, I have gotten this working as well, using gd-2.0.35. I messed up previously when trying to install it. I can make a spkg if you want, but you'd probably have to edit my attempts anyway.

-M.Hampton

(in reply to: ↑ 19 ) 09/22/2008 11:03:34 AM changed by mabshoff

Replying to mhampton:

OK, I have gotten this working as well, using gd-2.0.35. I messed up previously when trying to install it. I can make a spkg if you want, but you'd probably have to edit my attempts anyway. -M.Hampton

We are already using gd-2.0.35, so what changes do you propose to make? Either way, an jpeg.spkg would have to be voted in anyway.

Cheers,

Michael