GD problem with Joomla
-
- Joomla! Apprentice
- Posts: 6
- Joined: Thu Nov 05, 2009 12:11 am
GD problem with Joomla
i want to pull a image then draw on it and the destroy th eimage from memory so that it does not take room up on server. i had this working just as a php page outside of joomla, now i try to use the same code but incorporated into joomla and i get the following:
�PNG IHDRvW�W�� �IDATx���۸�y|ȧ=t{�6t�@"W��v� �Gi`� 4Ic�)i`f݀�4 � �~�B$>���)�\�����$#3���sf>��}���}G��3�0��w^x�x���������x�Zh�.coi.P�'X��ML/���:ȁ����~��zA�t���*��������L��L�X'��3�W�E��-� 3���+�܌�'.�6�o�x�\7�d�����Ȉ��c�3䕪�����ga��y��Y0��]4�ɨx&���;Ҕ�#g��_�֊�&��y����g��mm�p�!�L�8-�Hyi�Q����Y07cA�ٗ�M�L�Щm�g��0'c�=� �������.艾��3��}U� ��B{�S@_��s�8g]�|n�S_���=z��kY��C�[�X�9��m�9u���y>�ڇ��[pơ�Z������f�cv�m�X0�^)�;c�s0.��s,%��c"�0�(.��O}z4e����`�^)�N��93�v�Ը���m��v6\;c�JX�~�����uɌ����B+~j\���y���=�� �b�FF�-Z����k��#��4g���90�0W�r��L��dQ�`�N���.���92]{�X{����?s�~Zy���\�v�̏h-�#u�:��P �lbqG��"qv��L��<_�Gs�Ƒ��_ ��vό�P东}*�CB�[N��m���WBnL�ژ~�@k�S[Byl�n�)���4�EZE��#}bWӑ?�I1u��̑sO��g}�6�TOADq���=0�_n��a7]�n,������!h��(賃/O�oy/�<_̻� �!�=�}tr�;��;���uA�]�:�+%���p70�R����~7&!C�*O������IS��ӾN5�]s�n��,���}#|��)�9�Z��6Ͼ�P��osw'��V/U$�+v7��!��6���@Xٻ�2�����пeb�TE�^%�s��!Ӟ��^�*�=�.�Z(�&(�=��SX�rs���~q���u�v�����о����]?0��Ѿ��,���hq,��BO;��l��N{���m���\Z�䑴���Ī!�pR��X�#M�x�gJ�Զg�aME��.�^������IΩ�Ɲ�t�X�RS\�-�V�8b�S���ʔj��! �X7�D5�و>cl����x�8�eZ-04}(�{��H��L���8��U����.1�����#4�hQ����J ���-����X�=� zR��{��ϡh��P%�'��waV�"#ec������V����1�?�Eᆴ���Ėv��?����Ca��^ٍ oK�ƭ� �ĎՏ�m�fhe��N�ݣ[�'�s��k�:���oj�@��%�@*9eOk�� � ��+�vmW9�>��M������*�4�"��,���qCs�}�{w���91�]����4I�]�؝�}溌����{v�1�b���{���y�c�VV�b�(P�#��cc���9���j�m)]1��6�] �֧N����.y���|50QT�`�<�z��ȟ#�S{b�.�� �]k�ߙ�x�bӚ�L��^�<���wl]U��a��tBx�-sI�N�ő,t�2�}S�);�"��6�G� �B��)�r�+�.Ť��[Cw�'z�E���!�&ɰ�ߕB)b�Ij ���q�t�-�@֕�;�m�Lq?�ѯ����h�cX�*������W#��wsπwC�?V��d�5� =�ܒΰ���z�+�U��9f �F*����Њv�]�N܅� ���T����@W�ﵷ��In*te�kς���<�����wT�kx_�`d�=)
This is the coding that I using here. This same coding worked find out side joomla.
<?php
function resize($img, $w, $h, $newfilename) {
//Check if GD extension is loaded
if (!extension_loaded('gd') && !extension_loaded('gd2')) {
trigger_error("GD is not loaded", E_USER_WARNING);
return false;
}
//Get Image size info
$imgInfo = getimagesize($img);
switch ($imgInfo[2]) {
case 1: $im = imagecreatefromgif($img); break;
case 2: $im = imagecreatefromjpeg($img); break;
case 3: $im = imagecreatefrompng($img); break;
default: trigger_error('Unsupported filetype!', E_USER_WARNING); break;
}
//If image dimension is smaller, do not resize
if ($imgInfo[0] <= $w && $imgInfo[1] <= $h) {
$nHeight = $imgInfo[1];
$nWidth = $imgInfo[0];
}else{
//yeah, resize it, but keep it proportional
if ($w/$imgInfo[0] > $h/$imgInfo[1]) {
$nWidth = $w;
$nHeight = $imgInfo[1]*($w/$imgInfo[0]);
}else{
$nWidth = $imgInfo[0]*($h/$imgInfo[1]);
$nHeight = $h;
}
}
$nWidth = round($nWidth);
$nHeight = round($nHeight);
$newImg = imagecreatetruecolor($nWidth, $nHeight);
/* Check if this image is PNG or GIF, then set if Transparent*/
if(($imgInfo[2] == 1) OR ($imgInfo[2]==3)){
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent);
}
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $imgInfo[0], $imgInfo[1]);
header('Content-Type: image/png');
return imagepng($newImg);
}
$image = "lifestyle.png"; // File image location
$newfilename = "thumb_image.png"; // New file name for thumb
$w = 50;
$h = 50;
echo resize($image, $w, $h, $newfilename);
?>
I am also using joomla 1.5 and php GD. Please help us to solve this problem. I tried with
$doc =& JFactory::getDocument();
$doc->setMimeEncoding('image/png');
but result as same as that I got above. Please help
�PNG IHDRvW�W�� �IDATx���۸�y|ȧ=t{�6t�@"W��v� �Gi`� 4Ic�)i`f݀�4 � �~�B$>���)�\�����$#3���sf>��}���}G��3�0��w^x�x���������x�Zh�.coi.P�'X��ML/���:ȁ����~��zA�t���*��������L��L�X'��3�W�E��-� 3���+�܌�'.�6�o�x�\7�d�����Ȉ��c�3䕪�����ga��y��Y0��]4�ɨx&���;Ҕ�#g��_�֊�&��y����g��mm�p�!�L�8-�Hyi�Q����Y07cA�ٗ�M�L�Щm�g��0'c�=� �������.艾��3��}U� ��B{�S@_��s�8g]�|n�S_���=z��kY��C�[�X�9��m�9u���y>�ڇ��[pơ�Z������f�cv�m�X0�^)�;c�s0.��s,%��c"�0�(.��O}z4e����`�^)�N��93�v�Ը���m��v6\;c�JX�~�����uɌ����B+~j\���y���=�� �b�FF�-Z����k��#��4g���90�0W�r��L��dQ�`�N���.���92]{�X{����?s�~Zy���\�v�̏h-�#u�:��P �lbqG��"qv��L��<_�Gs�Ƒ��_ ��vό�P东}*�CB�[N��m���WBnL�ژ~�@k�S[Byl�n�)���4�EZE��#}bWӑ?�I1u��̑sO��g}�6�TOADq���=0�_n��a7]�n,������!h��(賃/O�oy/�<_̻� �!�=�}tr�;��;���uA�]�:�+%���p70�R����~7&!C�*O������IS��ӾN5�]s�n��,���}#|��)�9�Z��6Ͼ�P��osw'��V/U$�+v7��!��6���@Xٻ�2�����пeb�TE�^%�s��!Ӟ��^�*�=�.�Z(�&(�=��SX�rs���~q���u�v�����о����]?0��Ѿ��,���hq,��BO;��l��N{���m���\Z�䑴���Ī!�pR��X�#M�x�gJ�Զg�aME��.�^������IΩ�Ɲ�t�X�RS\�-�V�8b�S���ʔj��! �X7�D5�و>cl����x�8�eZ-04}(�{��H��L���8��U����.1�����#4�hQ����J ���-����X�=� zR��{��ϡh��P%�'��waV�"#ec������V����1�?�Eᆴ���Ėv��?����Ca��^ٍ oK�ƭ� �ĎՏ�m�fhe��N�ݣ[�'�s��k�:���oj�@��%�@*9eOk�� � ��+�vmW9�>��M������*�4�"��,���qCs�}�{w���91�]����4I�]�؝�}溌����{v�1�b���{���y�c�VV�b�(P�#��cc���9���j�m)]1��6�] �֧N����.y���|50QT�`�<�z��ȟ#�S{b�.�� �]k�ߙ�x�bӚ�L��^�<���wl]U��a��tBx�-sI�N�ő,t�2�}S�);�"��6�G� �B��)�r�+�.Ť��[Cw�'z�E���!�&ɰ�ߕB)b�Ij ���q�t�-�@֕�;�m�Lq?�ѯ����h�cX�*������W#��wsπwC�?V��d�5� =�ܒΰ���z�+�U��9f �F*����Њv�]�N܅� ���T����@W�ﵷ��In*te�kς���<�����wT�kx_�`d�=)
This is the coding that I using here. This same coding worked find out side joomla.
<?php
function resize($img, $w, $h, $newfilename) {
//Check if GD extension is loaded
if (!extension_loaded('gd') && !extension_loaded('gd2')) {
trigger_error("GD is not loaded", E_USER_WARNING);
return false;
}
//Get Image size info
$imgInfo = getimagesize($img);
switch ($imgInfo[2]) {
case 1: $im = imagecreatefromgif($img); break;
case 2: $im = imagecreatefromjpeg($img); break;
case 3: $im = imagecreatefrompng($img); break;
default: trigger_error('Unsupported filetype!', E_USER_WARNING); break;
}
//If image dimension is smaller, do not resize
if ($imgInfo[0] <= $w && $imgInfo[1] <= $h) {
$nHeight = $imgInfo[1];
$nWidth = $imgInfo[0];
}else{
//yeah, resize it, but keep it proportional
if ($w/$imgInfo[0] > $h/$imgInfo[1]) {
$nWidth = $w;
$nHeight = $imgInfo[1]*($w/$imgInfo[0]);
}else{
$nWidth = $imgInfo[0]*($h/$imgInfo[1]);
$nHeight = $h;
}
}
$nWidth = round($nWidth);
$nHeight = round($nHeight);
$newImg = imagecreatetruecolor($nWidth, $nHeight);
/* Check if this image is PNG or GIF, then set if Transparent*/
if(($imgInfo[2] == 1) OR ($imgInfo[2]==3)){
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent);
}
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $imgInfo[0], $imgInfo[1]);
header('Content-Type: image/png');
return imagepng($newImg);
}
$image = "lifestyle.png"; // File image location
$newfilename = "thumb_image.png"; // New file name for thumb
$w = 50;
$h = 50;
echo resize($image, $w, $h, $newfilename);
?>
I am also using joomla 1.5 and php GD. Please help us to solve this problem. I tried with
$doc =& JFactory::getDocument();
$doc->setMimeEncoding('image/png');
but result as same as that I got above. Please help
-
- Joomla! Apprentice
- Posts: 6
- Joined: Thu Nov 05, 2009 12:11 am
Re: GD problem with Joomla
Heeeeeeeee I solved the problem. This is the place I got a idea, how get my real image
http://stackoverflow.com/questions/1572 ... st#tab-top
1. First I created a new view call image
2. and view.raw.php and default.php file inside tmpl folder.
3. past my coding inside the default.php
4. Then access my page as fallow
http://mysite/index.php?option=com_myco ... format=raw
http://stackoverflow.com/questions/1572 ... st#tab-top
1. First I created a new view call image
2. and view.raw.php and default.php file inside tmpl folder.
3. past my coding inside the default.php
4. Then access my page as fallow
http://mysite/index.php?option=com_myco ... format=raw
-
- Joomla! Fledgling
- Posts: 2
- Joined: Sun Sep 12, 2010 6:13 am
Re: GD problem with Joomla
Dear anandafit or any expert in the forum,
I met exactly the same problem as you met. But I still can not figure it out after reading your post. Could you give me a little bit more directions?
1. First I created a new view call image
What is a view call image, is it an image or some code?
2. and view.raw.php and default.php file inside tmpl folder.
What is the code for view.raw.php?
3. past my coding inside the default.php
I suppose it is the same coding you posted on Feb 19, 2010
4. Then access my page as fallow
I suppose it is something like http://mysite/index.php?option=com_myco ... format=raw
Thank you very much.
I met exactly the same problem as you met. But I still can not figure it out after reading your post. Could you give me a little bit more directions?
1. First I created a new view call image
What is a view call image, is it an image or some code?
2. and view.raw.php and default.php file inside tmpl folder.
What is the code for view.raw.php?
3. past my coding inside the default.php
I suppose it is the same coding you posted on Feb 19, 2010
4. Then access my page as fallow
I suppose it is something like http://mysite/index.php?option=com_myco ... format=raw
Thank you very much.
-
- Joomla! Apprentice
- Posts: 6
- Joined: Thu Nov 05, 2009 12:11 am
Re: GD problem with Joomla
Hi deliang,
Actually I did this one before seven six months early so I could not remember what I did exactly.
The content of view.raw.php is fallow as I remember.
<?php
defined( '_JEXEC' ) or die;
jimport( 'joomla.application.component.view');
class YourcomponentnamehereViewImage extends JView
{
public function display($tpl = null)
{
$document =& JFactory::getDocument();
$document->setMimeEncoding('image/png');
// your image processing & output here
}
}
here "image" is not a text file, it is folder name of my view. Hope u know about joomla views. Seems to be ur URL and my one is same. I am very sorry about my memory.
Thanks,
Ananda,
blog@http://top-web-assist.[URL banned].com
Actually I did this one before seven six months early so I could not remember what I did exactly.
The content of view.raw.php is fallow as I remember.
<?php
defined( '_JEXEC' ) or die;
jimport( 'joomla.application.component.view');
class YourcomponentnamehereViewImage extends JView
{
public function display($tpl = null)
{
$document =& JFactory::getDocument();
$document->setMimeEncoding('image/png');
// your image processing & output here
}
}
here "image" is not a text file, it is folder name of my view. Hope u know about joomla views. Seems to be ur URL and my one is same. I am very sorry about my memory.
Thanks,
Ananda,
blog@http://top-web-assist.[URL banned].com
-
- Joomla! Fledgling
- Posts: 2
- Joined: Sun Sep 12, 2010 6:13 am
Re: GD problem with Joomla
Hello anandafit,
Thank you very much for your timely reply.
Unfortunately, I don't know joomla views. Is it a component or a module, or a plug in?
I searched in google, and it seems there is a website called www.joomlaviews.com. It is related to the news in joomla community and it doesn't seem relevant.
Could you show me any link related to joomla views?
Best Regards,
Deliang
Thank you very much for your timely reply.
Unfortunately, I don't know joomla views. Is it a component or a module, or a plug in?
I searched in google, and it seems there is a website called www.joomlaviews.com. It is related to the news in joomla community and it doesn't seem relevant.
Could you show me any link related to joomla views?
Best Regards,
Deliang
-
- Joomla! Apprentice
- Posts: 11
- Joined: Tue Jul 26, 2011 5:51 pm
Re: GD problem with Joomla
Hi Deliang,
Did you get this working? I'm in exactly the same boat and aint got a clue....
Did you get this working? I'm in exactly the same boat and aint got a clue....
- Per Yngve Berg
- Joomla! Master
- Posts: 30929
- Joined: Mon Oct 27, 2008 9:27 pm
- Location: Romerike, Norway
-
- Joomla! Apprentice
- Posts: 11
- Joined: Tue Jul 26, 2011 5:51 pm
Re: GD problem with Joomla
Hi Per Yngve Berg,
Yes I know what a view is (well at the top level) but I have no idea how to implement one in the context of getting a GD Image to display correctly.
Are you 'saying' that I will have to develop a MVC component to display a GD image that I want generated from a script despite the image itself showing correctly, and complete, if I use:
Yes I know what a view is (well at the top level) but I have no idea how to implement one in the context of getting a GD Image to display correctly.
Are you 'saying' that I will have to develop a MVC component to display a GD image that I want generated from a script despite the image itself showing correctly, and complete, if I use:
Code: Select all
<img src="image.php" >
- Per Yngve Berg
- Joomla! Master
- Posts: 30929
- Joined: Mon Oct 27, 2008 9:27 pm
- Location: Romerike, Norway
Re: GD problem with Joomla
Cannot you just insert it as an image into the article?
Have you checked if an extension exists?
PS. You should ask your question by starting a new topic instead of posting in an old one that is about something else.
Have you checked if an extension exists?
PS. You should ask your question by starting a new topic instead of posting in an old one that is about something else.
-
- Joomla! Apprentice
- Posts: 11
- Joined: Tue Jul 26, 2011 5:51 pm
Re: GD problem with Joomla
It works when inserting as an image but I need it generate from fields of a form. When I call the script it displays the raw png data as the original post.
No this is a custom form and image generation so there's no extensions.
I did start my own thread but no one has replied so I thought I'd post here too since the previous poster couldn't work it out either and I can't understand anandafit's solution. This thread is related. It is exactly the same issue.
No this is a custom form and image generation so there's no extensions.
I did start my own thread but no one has replied so I thought I'd post here too since the previous poster couldn't work it out either and I can't understand anandafit's solution. This thread is related. It is exactly the same issue.
- Per Yngve Berg
- Joomla! Master
- Posts: 30929
- Joined: Mon Oct 27, 2008 9:27 pm
- Location: Romerike, Norway
Re: GD problem with Joomla
What extension do you use to make the form?
-
- Joomla! Apprentice
- Posts: 11
- Joined: Tue Jul 26, 2011 5:51 pm
Re: GD problem with Joomla
Hmmm, I don't. I've written my own.....but hold on a wee second....I have chronoforms. Are you going to suggest that I modify something in there and include my script? Is that possible?
- Per Yngve Berg
- Joomla! Master
- Posts: 30929
- Joined: Mon Oct 27, 2008 9:27 pm
- Location: Romerike, Norway
Re: GD problem with Joomla
Yes, it should be possible to put in the Form Code tab.
-
- Joomla! Apprentice
- Posts: 11
- Joined: Tue Jul 26, 2011 5:51 pm
Re: GD problem with Joomla
Ah yes. However, I believe this is more a GD Image issue and may still require the code putting somewhere. Saying that though it gives me something else to search.
-
- Joomla! Intern
- Posts: 61
- Joined: Tue Feb 20, 2007 4:49 pm
Re: GD problem with Joomla
Just wondering if any posters in this thread have any updates about this topic.
I'm looking to solve the exact same issue, with no results yet.
Thanks.
I'm looking to solve the exact same issue, with no results yet.
Thanks.