what does jpg:- do?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
james438
Posts: 4
Joined: 2012-01-16T22:42:05-07:00
Authentication code: 8675308

what does jpg:- do?

Post by james438 »

Hi,

I am pretty new here, so please let me know if I am posting in the wrong place.

I am also new to ImageMagick as well and am casually trying to learn some of the basics. In the following example what does jpg:- do?

Code: Select all

<?php
 header( 'Content-Type: image/jpg' );
 system("convert images/pops/gdsample1.jpg -flop jpg:-");
 ?>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: what does jpg:- do?

Post by fmw42 »

It sends a jpg file to standard output (generally so that it can be piped to standard input to be processed by some other convert statement or some non-IM tool). You would be better creating a saved file with a given name.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: what does jpg:- do?

Post by Bonzo »

I can not remember if -flop is mirror in x axis or y axis. The code you have will mirror the photo in one axis and then display without saving it.
james438
Posts: 4
Joined: 2012-01-16T22:42:05-07:00
Authentication code: 8675308

Re: what does jpg:- do?

Post by james438 »

Ah, thank you. It was my suspicion that ":-" would somehow stop any permanent changes from being made, such as by using the "-write" command.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: what does jpg:- do?

Post by fmw42 »

You do not need to use -write to save an output image

convert image.jpg -flop result.jpg

will do fine, by just specifying a filename and suffix.

Use -write to save intermediate images or multiple output images, except for the last image.
james438
Posts: 4
Joined: 2012-01-16T22:42:05-07:00
Authentication code: 8675308

Re: what does jpg:- do?

Post by james438 »

Thank you, -write makes more sense now. I had been thinking of ImageMagick operating more like css. I still have one more question about my initial script though. What does the ending colon and dash located right before the closing quote do?

Thanks again for your explanations.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: what does jpg:- do?

Post by fmw42 »

jpg:-
In your command this says to send a jpg format image (that is the jpg:) to standard output (that is the -) without writing the file to disk.
james438
Posts: 4
Joined: 2012-01-16T22:42:05-07:00
Authentication code: 8675308

Re: what does jpg:- do?

Post by james438 »

Awesome, thanks :)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: what does jpg:- do?

Post by Bonzo »

Out of interest you are not using MagickWand for php but you are using the command line. I would post in the users section next time.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: what does jpg:- do?

Post by anthony »

james438 wrote:Hi,

I am pretty new here, so please let me know if I am posting in the wrong place.

I am also new to ImageMagick as well and am casually trying to learn some of the basics. In the following example what does jpg:- do?

Code: Select all

<?php
 header( 'Content-Type: image/jpg' );
 system("convert images/pops/gdsample1.jpg -flop jpg:-");
 ?>
In your specific case this PHP, outputs a bare minimum HTTP protocol header, followed but the image that the header indicates folows. This is typically run by the web server (like apache), which may add extra header items, then pass it to the client.

In other words calling the PHP script via a web client/browser, returns a JPG image, regardless of the image source format (though it is JPEG in this case), any extra modifications (-flop), and without needing a temprary file, or any save of the modified image to disk on the web server machine (client browsers would probably save it).

A good addition to this PHP script may be the inclusion of a 'timestamp' in the header based on the source image file timestamp (and the scripts own time stamp, whatever is newer), as the destination image will not change unless the source image or script changes. This prevents client browsers for needing to 'reload' the image when they already have a valid copy that does not change. Saves a lot of extra traffic and work on the both client and server machines!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply