473,378 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Image Compression Problem

AMT India
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 1224

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

Similar topics

3
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...
4
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...
6
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...
12
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...
1
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...
1
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...
7
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....
10
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...
3
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...
6
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.