473,385 Members | 1,642 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,385 software developers and data experts.

Having difficulty changing DPI on JPEG with PHP

I need a solution to automatically change the DPI of uploaded photos from 300 to 72. I've coded this bit of script to read the 14th through 18th bit of binary data of a JPEG and update the DPI. The script below seems to be writing to the jpeg, but the afterwards, the jpeg is unreadable and when I rerun the script, it still shows the image DPI hasn't changed. Anyone have experience changing DPI of an image?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.   $filename = 'familyshot33.jpg';
  4.  
  5.   // open file for writing
  6.   $f = fopen($filename, 'r+');
  7.  
  8.   $string = fread($f,20);
  9.   // show dpi before 
  10.   echo hexdec(bin2hex(substr($string, 14, 2))) . ' ' . hexdec(bin2hex(substr($string, 16, 2))) .'<br/>';
  11.  
  12.   // update dpi
  13.   $image = substr_replace($string, pack("Cnn", 0x01, 72, 72), 13, 5);
  14.  
  15.   // show dpi after
  16.   echo hexdec(bin2hex(substr($image, 14, 2))) . ' ' . hexdec(bin2hex(substr($image, 16, 2))) .'<br/>';
  17.  
  18.   // write and close
  19.   fwrite($f, $image,  filesize($filename));
  20.   fclose($f);
  21.  
  22. ?>
  23.  
May 28 '08 #1
1 4422
pbmods
5,821 Expert 4TB
Heya, Markurxn. Welcome to Bytes!

You may find this thread to be of some interest.
May 29 '08 #2

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

Similar topics

3
by: Ming | last post by:
Hi All, I want to write a PHP webpage which allows people to upload images (no matter what formats) to me and at the same time converts any non-jpeg image to JPEG. Here's what I have: ...
3
by: JJM | last post by:
Can anyone please help me with this I'm a total newbie and just getting started in JS. I have a page where I would like to display a picture and a short textual explanation of the picture. I...
1
by: Sean | last post by:
i am writing a class that visual demonstrates the result of changing the quality of a jpeg. the intention is to do this by saving the file and a selected quality, then reloading it to get an idea of...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
1
by: Tim Marshall | last post by:
I've just received a new computer with Win XP Version 5.1.2600. I want to have Access 2003 and Access 97 running on this, so I did some googling on cdma and it seems I must install these versions...
1
by: Samridhi Kumar Shukla | last post by:
I am facing technical difficulti in using server connection control because we cannot change the path once fixed .. one way is to edit the code of the form generated code but though it allow to...
2
by: Onwuka Emeka | last post by:
is there a way to reduce or modify the color depth of a jpeg image, i currently need to programatically change the color depth of a jpeg image from 24bits to 8bits. any help would be appreciated
2
by: Max2006 | last post by:
Hi, I am using a asp.net hosting service and I don't have access to IIS MMC. I would like to implement a URL rewriting service so all urls with shape: http://domainname.com/nnnn.jpeg get...
9
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.