Welcome Guest, Not a member yet? Register   Sign In
Converting Image Formats
#1

[eluser]cassy[/eluser]
Hey guys, this is my first post here. I'm new to PHP and CI and I love it! :-)

As I'm so new, I hope someone can help me. How do I use the Image Manipulation Class to convert between file formats?

Lets say I have a .PNG file on my server; how can I convert this to a .JPG format?

I'm looking forward to your replies.

Thanks.
Cassy.
#2

[eluser]vbsaltydog[/eluser]
There are no reformat methods in the class:

http://ellislab.com/codeigniter/user-gui...e_lib.html

however, since the class does support all three of the major image libraries, you can extend the class and add a reformat method.
#3

[eluser]Jason Stanley[/eluser]
I only had 2 minutes to look at this. The image lib class looks at the extension of the new image config variable. I assume it then outputs the correct image type based on the extension. Have you actually tried setting the $config['new_image'] variable? You could always then unlink the current image to get rid of the duplicate image.
#4

[eluser]cassy[/eluser]
@vbsaltydog
I'm not sure how I can do that. My version of XAMP on Windows only has the GD library.


@jason
If the source is a PNG and I specify the target to be a JPG, it saves as a new "JPG" but it is really a PNG with a JPG extension!

#5

[eluser]Jason Stanley[/eluser]
That sounds like a bug to me. You should log it on GitHub.

In the meantime you can either find another library or write something yourself.

I would start here:
http://www.php.net/manual/en/function.im...rompng.php

Then:
http://www.php.net/manual/en/function.imagejpeg.php

Its super easy.
#6

[eluser]cassy[/eluser]
@jason,
That scares me. I'm very new at this and it's very daunting.

Can someone compile the ImageMagick library into a DLL file for me?
I don't really know account compiling stuff like that and I can't find the DLL anywhere.
#7

[eluser]vbsaltydog[/eluser]
Where is your application eventually going to reside? On a Windows Server or a Linux Server? If a Linux Server, you don't want to use a dll and FWIW, most developing is done in a *nix environment.
#8

[eluser]Jason Stanley[/eluser]
Cassy.. what is daunting about the PHP manual?

What is so hard about doing doing this!? A + B = C

Code:
$image = imagecreatefrompng('path/to/image');
imagejpeg($image, 'path/to/new/image');
imagedestroy($image);

To get better you read and experiment. If you can't even be bothered to do that I don't know why you are programming...
#9

[eluser]cassy[/eluser]
@vbsaltydog
I'm not sure. I'm doing this to learn so that I can apply to a college next year. I already do web design but I want to be a "Web Developer". My dad said that's where the money is. I don't know much about Linux. I only have access to a Windows 7 computer and am running XAMP + CI.

@jason
Interesting. Thanks for the Tip.

Can you tell me how I can programatically determine if a file is an image and not a, lets say a malicious .PHP file renamed to a .JPG file?
#10

[eluser]vbsaltydog[/eluser]
http://php.net/manual/en/ref.image.php




Theme © iAndrew 2016 - Forum software by © MyBB