Skip to content

Commit

Permalink
[php] Support PNG output without GD.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsky committed Jan 6, 2013
1 parent 7963070 commit 6296662
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
50 changes: 33 additions & 17 deletions php/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ PHP_ARG_ENABLE(qr, [whether to enable QR Code support],

PHP_ARG_ENABLE(qr-gd, [whether to QR Code GD support],
[ --enable-qr-gd Enable GIF, JPEG, PNG, WBMP output support
by the PHP GD extension], yes, no)
by the PHP GD extension], no, no)

PHP_ARG_WITH(qr-png, [whether to QR Code PNG support],
[ --with-qr-png[[=DIR]] Enable PNG output support.
DIR is zlib install prefix], yes, no)

PHP_ARG_WITH(qr-tiff, [whether to QR Code TIFF support],
[ --with-qr-tiff[[=DIR]] Enable zlib compressed TIFF output support.
[ --with-qr-tiff[[=DIR]] Enable TIFF output support.
DIR is zlib install prefix], no, no)

if test "$PHP_QR" != "no"; then
Expand All @@ -36,13 +40,27 @@ if test "$PHP_QR" != "no"; then
AC_DEFINE(PHP_QR_GD_BUNDLED, 1, [use gd extension])
AC_DEFINE(QR_ENABLE_GD, 1, [enable GD support in libqr])
QR_SOURCES="$QR_SOURCES libqr/qrcnv_gd.c"

PHP_QR_PHP_VERNUM=`"$PHP_CONFIG" --version | $AWK -F. '{ printf "%d", ($1 * 100 + $2) * 100 }'`
if test "$PHP_QR_PHP_VERNUM" -ge 50300; then
QR_SOURCES="$QR_SOURCES gd_wrappers.c"
AC_DEFINE(PHP_QR_USE_GD_WRAPPERS, 1, [ ])
else
AC_DEFINE(PHP_QR_USE_GD_WRAPPERS, 0, [ ])
fi
else
AC_DEFINE(PHP_QR_USE_GD_WRAPPERS, 0, [ ])
fi

dnl
dnl Check the zlib support
dnl
if test "$PHP_QR_TIFF" != "no"; then
if test "$PHP_QR_TIFF" != "yes"; then
if test "$PHP_QR_PNG$PHP_QR_TIFF" != "nono"; then
if test "$PHP_QR_PNG" != "yes"; then
if test -r "$PHP_QR_PNG/include/zlib.h"; then
QR_ZLIB_DIR="$PHP_QR_PNG"
fi
elif test "$PHP_QR_TIFF" != "yes"; then
if test -r "$PHP_QR_TIFF/include/zlib.h"; then
QR_ZLIB_DIR="$PHP_QR_TIFF"
fi
Expand Down Expand Up @@ -82,22 +100,20 @@ if test "$PHP_QR" != "no"; then
-L$QR_ZLIB_DIR/lib
])

AC_DEFINE(PHP_QR_ENABLE_TIFF, 1, [enable TIFF support])
AC_DEFINE(QR_ENABLE_TIFF, 1, [enable TIFF support in libqr])
QR_SOURCES="$QR_SOURCES libqr/qrcnv_tiff.c"
if test "$PHP_QR_PNG" != "no"; then
AC_DEFINE(PHP_QR_ENABLE_PNG, 1, [enable PNG support])
AC_DEFINE(QR_ENABLE_PNG, 1, [enable PNG support in libqr])
QR_SOURCES="$QR_SOURCES libqr/qrcnv_png.c"
fi
if test "$PHP_QR_TIFF" != "no"; then
AC_DEFINE(PHP_QR_ENABLE_TIFF, 1, [enable TIFF support])
AC_DEFINE(QR_ENABLE_TIFF, 1, [enable TIFF support in libqr])
QR_SOURCES="$QR_SOURCES libqr/qrcnv_tiff.c"
fi
fi

PHP_ADD_INCLUDE(./libqr)
PHP_ADD_INCLUDE(libqr)
PHP_SUBST(QR_SHARED_LIBADD)
AC_DEFINE(HAVE_QR, 1, [ ])

GDEXTRA_PHP_VERNUM=`"$PHP_CONFIG" --version | $AWK -F. '{ printf "%d", ($1 * 100 + $2) * 100 }'`
if test "$GDEXTRA_PHP_VERNUM" -ge 50300; then
QR_SOURCES="$QR_SOURCES gd_wrappers.c"
AC_DEFINE(PHP_QR_USE_GD_WRAPPERS, 1, [ ])
else
AC_DEFINE(PHP_QR_USE_GD_WRAPPERS, 0, [ ])
fi

PHP_NEW_EXTENSION(qr, $QR_SOURCES , $ext_shared)
fi
15 changes: 14 additions & 1 deletion php/php_qr.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,9 @@ static ZEND_INI_MH(QrOnUpdateFormat)
*p = QR_FMT_PNG;
} else if (value_length == 4 && strcasecmp("wbmp", value) == 0) {
*p = QR_FMT_WBMP;
#elif PHP_QR_ENABLE_PNG
} else if (value_length == 3 && strcasecmp("png", value) == 0) {
*p = QR_FMT_PNG;
#endif
} else {
long foramt = zend_atoi(new_value, new_value_length);
Expand All @@ -846,8 +849,13 @@ static ZEND_INI_MH(QrOnUpdateFormat)
return FAILURE;
}
#endif
#if !defined(PHP_QR_ENABLE_PNG) && !defined(PHP_QR_GD_BUNDLED)
if (foramt == QR_FMT_PNG) {
return FAILURE;
}
#endif
#ifndef PHP_QR_GD_BUNDLED
if (foramt == QR_FMT_GIF || foramt == QR_FMT_JPEG || foramt == QR_FMT_PNG || foramt == QR_FMT_WBMP) {
if (foramt == QR_FMT_GIF || foramt == QR_FMT_JPEG || foramt == QR_FMT_WBMP) {
return FAILURE;
}
#endif
Expand Down Expand Up @@ -999,8 +1007,13 @@ PHP_MINIT_FUNCTION(qr)

#ifdef PHP_QR_GD_BUNDLED
QRCODE_DECLARE_CONSTANT_EX(GD_ENABLED, 1L);
QRCODE_DECLARE_CONSTANT_EX(PNG_ENABLED, 1L);
#elif defined(PHP_QR_ENABLE_PNG)
QRCODE_DECLARE_CONSTANT_EX(GD_ENABLED, 0);
QRCODE_DECLARE_CONSTANT_EX(PNG_ENABLED, 1L);
#else
QRCODE_DECLARE_CONSTANT_EX(GD_ENABLED, 0);
QRCODE_DECLARE_CONSTANT_EX(PNG_ENABLED, 0);
#endif
#ifdef PHP_QR_ENABLE_TIFF
QRCODE_DECLARE_CONSTANT_EX(TIFF_ENABLED, 1L);
Expand Down

0 comments on commit 6296662

Please sign in to comment.