Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Convert Gif & Png To Jpeg


12 replies to this topic

#1 Rojay

    Newbie

  • Kontributors
  • Pip
  • 4 posts

Posted 08 August 2005 - 07:07 AM

how can i convert gifs and pngs to jpeg using php ??

#2 guangdian

    Trap Grand Marshal Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,187 posts
  • Interests:Nothing

Posted 08 August 2005 - 10:07 AM

Oh if you just got the ACDsee you will convert it by ACDsee
if you not installing it.i think photoshop can do it.
but
there is so lots of programme (open source or not opensource ) you can just trying them just search on enginne for this sort of programmes.

GoodLuck
Guangdian. -_-

#3 clagnol

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 186 posts
  • Location:Wichita, KS
  • Interests:I want to laugh,<br />I want to play,<br />I want to spell &quot;Mississippi&quot;,<br />And get an &quot;A&quot;<br /><br />I want to dance,<br />I want to sing,<br />I want to do everything!<br /><br />(Taken from an early 90's pro-life commercial)
  • myCENT:ZERO

Posted 08 August 2005 - 11:33 AM

Lol. I don't think guangdian understands the question.

But, I'm interested to know the answer, too. The Facebook employs a script to do this.

#4 rvalkass

    apt-get moo

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,107 posts
  • Gender:Male
  • Location:Devon, England
  • Interests:At the moment, Physics mainly!
  • myCENT:69.42
  • Spam Patrol

Posted 08 August 2005 - 12:55 PM

There is a way. You would have to upload the file, open it, start a blank picture with the same dimentions and add the first image to it then save it as a .jpg under a different name.
I'll have a go and see if I can get a script to work.

#5 truefusion

    Coincidence is non-sequitur, therefore everything has a reason for its existence (except if they are eternal).

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,216 posts
  • Gender:Male
  • Location:No, not there. Not there either. Yes, you'll never figure it out.
  • Interests:God, Christianity.
  • myCENT:86.16

Posted 08 August 2005 - 03:28 PM

I use Irfan View to convert Images. I believe it's still freeware.

#6 mizako

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 372 posts
  • Location:Spain
  • Interests:Computers, Usability, Internet, Web development, programming languages, soccer

Posted 08 August 2005 - 04:57 PM

I think some of you missunderstood the question. The guy is looking for a script to transform in the fly pictures from png & gif to jpg. You should look for functions such as fopen fwrite and particular from php to manage those extensions. I do not know the names of those functions by head but it should not take you a lot to look for them in google or directly in the php manual.

#7 DoR

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 59 posts

Posted 08 August 2005 - 05:35 PM

A simple way is, if you have installed imagemagick, upload the image and call to "convert" binary to convert from one format to another.
It is simple and powerfull.

The web site of imagemagick is http://www.imagemagick.org/
It is based on GPL license and can be installed on linux, solaris, windows, mac os x, freebsd,...

These are two links to pages explaining the usage of imagemagick from php:
1) Link 1
2) Link 2


If you have the images already on the server, you should convert them all only once.

Hope usefull.
DoR.

#8 alexia

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 310 posts
  • Location:Italian
  • Interests:None

Posted 09 August 2005 - 09:06 PM

Use Adobe Photoshop for image convert -_-
for web application visit and search in www.hotscripts.com :P

#9 HmmZ

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 362 posts
  • Location:The Netherlands

Posted 15 August 2005 - 08:03 PM

People reply with useless replys really...

But what you're asking for is not an easy function, it will need to use mysql databases aswell....
guess ill give it a go ..

First: make a mysql table
CREATE TABLE images (
img_id int(9) NOT NULL auto_increment,
img_file varchar(13) NOT NULL default '',
img_type enum('JPG','PNG') NOT NULL default 'JPG',
img_height int(6) NOT NULL default '0',
img_width int(6) NOT NULL default '0',
img_bytes int(9) NOT NULL default '0',
img_title text NOT NULL,
img_descr text NOT NULL,
img_alt text NOT NULL,
PRIMARY KEY (img_id)
) TYPE=MyISAM;
The table is needed to store the images, converted images and to insert,update and retrieve image info

Next:
//Define dirs
$base_img_dir = "./img/";
$img_conv_dir = "./bin/";

//Image table
$img_table = "images";

//Database connection !!needs your info!!
mysql_connect("host", "user", "pass");
mysql_select_db("yourtable");

//Generate a unique image property..id
$uniq = uniqid("");

// new file name
$filename = $base_img_dir.$uniq;

//Get image size
$imginfo = getimagesize($filename);


//Get image extension
function image_type_to_extension($imagetype,$include_dot=false)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case IMAGETYPE_GIF: return 'gif';
case IMAGETYPE_JPEG: return 'jpg';
case IMAGETYPE_PNG: return 'png';
case IMAGETYPE_SWF: return 'swf';
case IMAGETYPE_WBMP: return 'wbmp';
default: return false;}}

//full image name
$Dot='.';
$image="$filename$Dot$imagetype";

//find non jpg
if(($imagetype==gif) || ($imagetype==png) || ($imagetype==swf) || ($imagetype==wbmp)){
$imagetype='jpg';

//Remove original and rename new to save space
unlink($filename);
$jpgimg=$filename$imagetype;

//preload check
if($imagetype=!'jpg'){
$imagetype='jpg;
$Dot='.';
$jpgimg="$filename$Dot$imagetype;}

//Load image to check correct handling
$img = imagecreatefromjpg($filename);
imagejpg($img, $filename);
imagedestroy($img);

//Done...get it into your db
// insert image into db
mysql_query("INSERT INTO $img_table (img_file, img_type, img_height,
img_width, img_bytes, img_title, img_descr, img_alt)
VALUES('$uniq', '$img_type', ".$imginfo[1].", ".$imginfo[0].",
$imgbytes, '".addslashes($HTTP_POST_VARS["title"])."', '".
addslashes($HTTP_POST_VARS["descr"])."',
'".addslashes($HTTP_POST_VARS["alt"])."');");

//Last chance on failure..
if($filename$Dot$imagetype=!$filename.jpg){
$color="#ff0000"';
$result = "Sorry, Image conversion failed";;}
else {
$color="#06FF00";
$result = "Success! Your image was successfully converted to the .JPG extension!";}

//Result screen
echo "Your Image: ".$filename$Dot$imagetype."";
echo "<br>";
echo "has received the following result:";
echo "<br>";
echo "<font color=\"".$color."\">$result</font>";

I am (of course) unsure if this qorks, but it's a step in the right way ( i think i do know a bit of PHP o.O;-_-..

Hope this helps you

#10 bluedragon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 384 posts
  • Gender:Male
  • Location:Jupiter
  • myCENT:26.63

Posted 24 April 2008 - 09:53 AM

I've seen a C library for converting images but what you are asking I am really unsure.

I can understand that png to jpeg is possible but Gif to jpeg i don't know. because in most of the cases Gifs are in motion.

kindly clear your question.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users