Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert files
#1
Hi everyone

May I ask if there's a way to convert files from one extension to the other using php?
Like:
.doc to.docx
.png to .jpg
.avi to .mp4

I saw that to convert .avi to .mp4 need ffmpeg. What about the other two? 

Thanks
Reply
#2
You can use ImageMagick's convert application to convert images to different formats and much more or you can use the gd library, too.

Check examples below:
- http://stackoverflow.com/a/14549647
- http://stackoverflow.com/a/21120150
- http://php.net/manual/en/imagick.setimageformat.php
- http://theonlytutorials.com/convert-imag...if-in-php/
Reply
#3
Thanks. What about documents? Like .doc to .docx? ImageMagick and gd are for pictures only. For the .avi to .mp4 are there alternatives other than ffmpeg?
Reply
#4
(12-19-2016, 08:45 AM)jacktay Wrote: Thanks. What about documents? Like .doc to .docx? ImageMagick and gd are for pictures only. For the .avi to .mp4 are there alternatives other than ffmpeg?

Does your office app have any kind of scripting or macros? Generally I would not use automation for such things because the conversion is rarely perfect and having to check is probably not much more time consuming than just converting manually. 

Same with images really. Unless you have loads to convert. It depends on the content of each image, some, like screenshots will compress just as well with .png and be much better quality. If there's a lot of blocks the same color they will compress well without loss. 

Even with the ones that will benefit from conversion to .jpg, you can get away with more or less compression depending on the image content. 

Just a thought. If you have loads of stuff to convert I guess you don't have a choice.
Andy

[Edit} Sorry I meant to add, You could look into google's apis, google docs can do the conversion, so it's probably there somewhere in their apis. Here's a starting point: https://developers.google.com/drive/v2/w...oogle_docs
Internet Freedom for groups, schools and individuals in Africa
friendsvps.org
Reply
#5
Im trying to convert these files using php code on a server. Basically the user uploads a file and if it is unsupported, a particular php page will do the conversion. How to do that?
Reply
#6
(12-20-2016, 10:12 AM)jacktay Wrote: Im trying to convert these files using php code on a server. Basically the user uploads a file and if it is unsupported, a particular php page will do the conversion. How to do that?

Not sure exactly how, but the google api will do it. May be hard to wade through the complications of "how", being google, you know! I imagine it would mean putting the docs on google drive and then using the api to convert them on a page in your site. After being diverted into all sorts of irrelevant google "help" docs...
Andy
Internet Freedom for groups, schools and individuals in Africa
friendsvps.org
Reply
#7
Wow, never thought about it. I'll try and google, thanks.
So,
GD for graphics
google docs api for documents.
Then what about videos and audios??? Something else other than ffmpeg pls.
Reply
#8
Hi again in 2017

Thanks for the suggestions and replies from you guys!
I have found out that its easy to use ffmpeg. So I will just stick with ffmpeg first.
Anyway, my server is linux, and it has ffmpeg built in. Smile
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)