Page 1 of 1
it works or it dosent work gd image convertion gif to jpeg
Posted: Wed Jan 03, 2007 1:45 pm
by michael1991j
if found this function where i can convert gif to jpeg
i tested it it worked
Code: Select all
<?php
function gif2jpeg($p_fl, $p_new_fl='', $bgcolor=false){
list($wd, $ht, $tp, $at)=getimagesize($p_fl);
$img_src=imagecreatefromgif($p_fl);
$img_dst=imagecreatetruecolor($wd,$ht);
$clr['red']=255;
$clr['green']=255;
$clr['blue']=255;
if(is_array($bgcolor)) $clr=$bgcolor;
$kek=imagecolorallocate($img_dst,
$clr['red'],$clr['green'],$clr['blue']);
imagefill($img_dst,0,0,$kek);
imagecopyresampled($img_dst, $img_src, 0, 0,
0, 0, $wd, $ht, $wd, $ht);
$draw=true;
if(strlen($p_new_fl)>0){
if($hnd=fopen($p_new_fl,'w')){
$draw=false;
fclose($hnd);
}
}
if(true==$draw){
header("Content-type: image/jpeg");
imagejpeg($img_dst);
}else imagejpeg($img_dst, $p_new_fl);
imagedestroy($img_dst);
imagedestroy($img_src);
}
$fl='http://www.suchona.com/test/testgif.gif';
$c['red']=255;
$c['green']=255;
$c['blue']=255;
gif2jpeg($fl, '', $c);
?>
you can see it here
http://www.licut.com/weather/conver.php
then i tried this picture from noaa and then the script failed
Code: Select all
<?php
function gif2jpeg($p_fl, $p_new_fl='', $bgcolor=false){
list($wd, $ht, $tp, $at)=getimagesize($p_fl);
$img_src=imagecreatefromgif($p_fl);
$img_dst=imagecreatetruecolor($wd,$ht);
$clr['red']=255;
$clr['green']=255;
$clr['blue']=255;
if(is_array($bgcolor)) $clr=$bgcolor;
$kek=imagecolorallocate($img_dst,
$clr['red'],$clr['green'],$clr['blue']);
imagefill($img_dst,0,0,$kek);
imagecopyresampled($img_dst, $img_src, 0, 0,
0, 0, $wd, $ht, $wd, $ht);
$draw=true;
if(strlen($p_new_fl)>0){
if($hnd=fopen($p_new_fl,'w')){
$draw=false;
fclose($hnd);
}
}
if(true==$draw){
header("Content-type: image/jpeg");
imagejpeg($img_dst);
}else imagejpeg($img_dst, $p_new_fl);
imagedestroy($img_dst);
imagedestroy($img_src);
}
$fl='http://www.srh.noaa.gov/ridge/Conus/RadarImg/Conus_20070103_1838_N0Ronly.gif';
$c['red']=255;
$c['green']=255;
$c['blue']=255;
gif2jpeg($fl, '', $c);
?>
you can see it here
http://www.licut.com/weather/conver2.php
so what is the problem
is there like a limit in the config file for size or somthing like that
thank you in advance
Posted: Wed Jan 03, 2007 2:01 pm
by neophyte
There is a memory limit and a time limit. Usually the memory limit takes care of it.
Posted: Wed Jan 03, 2007 2:46 pm
by michael1991j
no good i put it in my script and i went php.ini and changed it
restarted my httpd
no good
and finaly i even hired the limit to 50
and it still didnt work
do you need a copy of my configuation file
Posted: Wed Jan 03, 2007 2:49 pm
by Kieran Huggins
what does it say when it fails?
Try just calling the image itself (not embedded in a web page) and "view source".
Posted: Wed Jan 03, 2007 2:53 pm
by bokehman
Your second script works for me (8MB) (16 seconds).
Posted: Wed Jan 03, 2007 3:22 pm
by michael1991j
mr canida it dosent say anything and the image is there
bokehman
did you try it on your server
if you did i may just get php config file and dispay it
fyed i know this is my third time editing my post
Posted: Wed Jan 03, 2007 3:27 pm
by bokehman
michael1991j wrote:did you try on you server
I don't understand what you are asking. PHP is server software so of course I tried it on a server. Are you asking if the server has public access? If so the answer is yes but I don't see the relevance.
Posted: Wed Jan 03, 2007 3:31 pm
by michael1991j
noo i was wondering if it was on your server because it could just be my bowser
well ok the next post is my config .ini
Posted: Wed Jan 03, 2007 3:45 pm
by michael1991j
Code: Select all
[PHP]
engine = On
zend.ze1_compatibility_mode = Off
short_open_tag = On
asp_tags = Off
precision = 14
y2k_compliance = On
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func=
serialize_precision = 100
allow_call_time_pass_reference = Off
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
disable_functions =
disable_classes =
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 12M
error_reporting = E_ALL
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
variables_order = "EGPCS"
register_globals = Off
register_long_arrays = Off
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
extension_dir = "/usr/lib/php/modules"
enable_dl = On
file_uploads = On
upload_max_filesize = 30M
allow_url_fopen = On
default_socket_timeout = 60
[Date]
[Syslog]
define_syslog_variables = Off
[mail function]
SMTP = localhost
smtp_port = 25
sendmail_path = /usr/sbin/sendmail -t -i
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[MySQL]
mysql.allow_persistent = On
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off
[MySQLi]
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mSQL]
msql.allow_persistent = On
msql.max_persistent = -1
msql.max_links = -1
[PostgresSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[Sybase]
sybase.allow_persistent = On
sybase.max_persistent = -1
sybase.max_links = -1
sybase.min_error_severity = 10
sybase.min_message_severity = 10
sybase.compatability_mode = Off
[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10
[bcmath]
bcmath.scale = 0
[browscap]
[Informix]
ifx.default_host =
ifx.default_user =
ifx.default_password =
ifx.allow_persistent = On
ifx.max_persistent = -1
ifx.max_links = -1
ifx.textasvarchar = 0
ifx.byteasvarchar = 0
ifx.charasvarchar = 0
ifx.blobinfile = 0
ifx.nullformat = 0
[Session]
session.save_handler = files
session.save_path = "/var/lib/php/session"
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[MSSQL]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatability_mode = Off
mssql.secure_connection = Off
[Assertion]
[Verisign Payflow Pro]
pfpro.defaulthost = "test-payflow.verisign.com"
pfpro.defaultport = 443
pfpro.defaulttimeout = 30
[COM]
[mbstring]
[FrontBase]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
sorry fyed for the size
feyd | It's feyd, not fyed. Consolidated structures.
Posted: Wed Jan 03, 2007 3:56 pm
by michael1991j
sorry i will try to rembember
Posted: Wed Jan 03, 2007 4:57 pm
by onion2k
Resampling an image to be the same size as the source image is a waste of time. You'll find things go quicker if you just open the image and then display or save it as a JPEG.
Code: Select all
function gif2jpeg($p_fl, $p_new_fl='', $bgcolor=false){
list($wd, $ht, $tp, $at)=getimagesize($p_fl);
$img_src=imagecreatefromgif($p_fl);
if(strlen($p_new_fl)>0){
if($hnd=fopen($p_new_fl,'w')){
$draw=false;
fclose($hnd);
}
}
if(true==$draw){
header("Content-type: image/jpeg");
imagejpeg($img_src);
} else {
imagejpeg($img_dst, $p_new_fl);
}
imagedestroy($img_src);
}
Posted: Wed Jan 03, 2007 6:29 pm
by michael1991j
i think you script has a bug
first it created the file like stated in the script but when you are writing to that file
you never gave the value to $img_dst that may be the problem
I may just be wrong
and stated the function wrong
but when i run the script it makes a file but i think it is not writing to the file
Code: Select all
<?php
function gif2jpeg($p_fl, $p_new_fl='', $bgcolor=false){
list($wd, $ht, $tp, $at)=getimagesize($p_fl);
$img_src=imagecreatefromgif($p_fl);
if(strlen($p_new_fl)>0){
if($hnd=fopen($p_new_fl,'w')){
$draw=false;
fclose($hnd);
}
}
if(true==$draw){
header("Content-type: image/jpeg");
imagejpeg($img_src);
} else {
imagejpeg($img_dst, $p_new_fl);
}
imagedestroy($img_src);
}
$fl='http://www.srh.noaa.gov/ridge/Conus/RadarImg/Conus_20070103_2018_N0Ronly.gif';
$c['red']=255;
$c['green']=255;
$c['blue']=255;
gif2jpeg($fl, 'image.jpeg', $c);
?>
Posted: Wed Jan 03, 2007 6:35 pm
by michael1991j
another thing to add is that i didn't realy know because i just found the script at
http://www.php.net
Posted: Thu Jan 04, 2007 2:54 am
by onion2k
imagejpeg($img_dst, $p_new_fl); should be imagejpeg($img_src, $p_new_fl); ... I missed that one.
another thing to add is that i didn't realy know because i just found the script at
http://www.php.net
Running code that you don't understand is a dangerous thing to do. It could introduce all sorts of bugs and security problems into your website.