473,657 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Image Compression Problem

AMT India
64 New Member
I have an image resizing function using GD Library in php.After resizing the gif images,they lose their animation properties.
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.                 $file_name_src =  $upload_file;
  4.             $file_desination2 = $compressedPath;
  5.  
  6.               list($width_orig, $height_orig, $type) = getimagesize($file_name_src);
  7.  
  8.  
  9.                 if($type == "1" )
  10.                 {
  11.                     $image = imagecreatefromgif($file_name_src);
  12.  
  13.                 }
  14.                 elseif ($type=="2")
  15.                 {
  16.                     $image = imagecreatefromjpeg($file_name_src);
  17.                 }
  18.                 elseif($type=="3")
  19.                 {
  20.                     $image = imagecreatefrompng($file_name_src);
  21.                 }
  22.                 //echo $image."<br/>";
  23.                 $new_width = $new_width;
  24.                 $new_height = $new_height;
  25.  
  26.                     if ($new_width && ($width_orig < $height_orig)) 
  27.                     {
  28.                         $new_width = ($new_height / $height_orig) * $width_orig;
  29.                     } 
  30.                     else 
  31.                     {
  32.  
  33.                         $new_height = ($new_width / $width_orig) * $height_orig;
  34.                     }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.                 // Resample
  41.                 $image_p = imagecreatetruecolor($new_width, $new_height);
  42.  
  43.                 //echo $image_p."<br/>";
  44.                 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
  45.  
  46.                 //echo $file_desination2;
  47.  
  48.  
  49.  
  50.                     if (function_exists("imagegif"))
  51.                     {        
  52.                         //header("Content-type: image/gif");
  53.                         imagegif($image_p,$file_desination2);
  54.                     }
  55.                     elseif (function_exists("imagejpeg"))
  56.                     {
  57.                         imagejpeg($image_p, $file_desination2, 100);
  58.                     } 
  59.                     elseif (function_exists("imagepng"))
  60.                     {
  61.                         imagepng($image_p,$file_desination2);
  62.                     }
  63.                     elseif (function_exists("imagewbmp")) 
  64.                     {
  65.                         imagewbmp($image_p,$file_desination2);
  66.                     } 
  67.                     else 
  68.                     {
  69.                         die("No image support in this PHP server");
  70.  
  71.                     }
  72.                      imagedestroy($image_p);
  73.                      chmod($file_desination2,0655);
  74.  
  75.                     return true;
  76.  
Regards,
AMTIndia
Jan 9 '08 #1
0 1243

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4661
by: CanyonJ | last post by:
I've been running into a frustrating problem for a while now. I use image.FromStream to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per pixel format, so there is some compression going on when we save the file. Quite a few files are opened and closed. Everything seems to work fine for a couple hours. The only draw back is the cpu is generally at 100%. Then the code starts...
4
1639
by: Al | last post by:
Hi I need to save lots of images on potentially very large database. Therefore the storage space is very crucial. I need what is most compact way to save an image. Currently I am using something like thi Thanks in advanc A dim IoImageValue() As Byt ….get the bytes from InkPictureBox control myDataRow("Graph") = IoImageValu
6
4569
by: Corobori | last post by:
I am writing a vb.net application where I need to store image in a SQL Server database, yes I know I shouldn't but my clients wants it and has his reasons to do so. In order to reduce the database size I was wondering how I could compress the image (coming from a scan made by Pegasus TwainPro). I saw some possibility in the TwainPro doc but the samples do not contain much description. I was thinking of using Xceed Streaming Compression to...
12
9255
by: Lance | last post by:
hey all, first time vb.net 2005 user, after sticking vb6 out for a long time... anyway, using this code ====================== Dim FS As FileStream = File.OpenRead(Filename) Dim theImage As Image Try theImage = Image.FromStream(FS, False, False)
1
1586
by: jitu78 | last post by:
GIF Images Use GIF files for images that have a small number of colors. GIF files are always reduced to no more than 256 unique colors. The compression algorithm for GIF files is less complex than for JPEG files, but when used on flat color images and text it produces very small file sizes. The GIF format is not suitable for photographic images or images with gradient colors. Because the GIF format has a limited number of colors, gradients...
1
3450
by: Stedak | last post by:
I have the following class I use to save Tiff's. The problem I have with it is that the final size of the images are very large. If we scan directly to a file the final tiff may be 600-900 kb.s but with this code it is often 4000-5000 kb.s. What am I missing? public class EmrTiff : IDisposable { private string fileName; private ArrayList imageContainer = null;
7
3781
by: Ben | last post by:
Hi We are looking for a component that offers that offers the below for Tiff files: Image clean-up (deskew, despeckle) Printing capabilities from VB The ability to add text to image, e.g. time / date Nice to have:
10
10705
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi, Please help me to write a dll in C# , that will read each pages of a tiff image from a file and a memory stream object ( need two ways) and creatre a new tiff image object.The dll should return the combined tif image object. Thnks in advance Rinu G P
3
1760
by: Victory | last post by:
Hi, I just used VS2008 and migrated a project from 2005 to 2008. The reason is that MSDN docs is saying the Image object in .NET Framework 3.5 has a Finalize method, which i want to try out since my app is processing a few image files and then saying it is running out of memory. I am using the Dispose method of this object to get rid of it and then setting it to Nothing. in any case, when i used VS 2008, intellisense still does not show...
6
7507
by: Victory | last post by:
Hi, I need to know the compression type of jpeg (jpg) files. I am using the System.Drawing.Imaging and loading the file using an Image object. The next thing i do, is to examine the propertyItems property of the object which gives me an ID, a type and Value. I am able to check for an ID of 259 (259 is the compression id) for Tiff images and check the value upper and lower significant bits of the value to see the compression. But i don't...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.